Write PEP8 Code: Display Full Name & Major

In summary: C. The first character of the data block is at 0x1E. The second character is at 0x1F. So the assembler is allocating two bytes of memory (with the DB directive) for the first name. Then the code is reading two characters from the input and storing them at the first and second byte of the data block, and then outputting the first and second byte of the data block. It just so happens that the first and second byte of the data block are the first and second characters of the first name field in the data block.In summary, your program should store the first name, middle name, last name, and major in a data block somewhere
  • #1
angeliKITTYx
8
0

Homework Statement


You are to write a program that will display your full name and your major (First Name, Middle name and Last Name) on the Terminal Input/output (I/O) screen.[/B]

Homework Equations

The Attempt at a Solution


I was trying to get the screen to say "What's your first name?" *store human input as name1*
"Middle name? *store input as name2* etc... and then it would print the full name and my major at the end,

BR main

name1: .WORD ? (or do I use .BYTE ?)
name2: .WORD ?
name3: .WORD ?
major: .WORD ?

main: .ASCII "What is your first name?"
LDA ?, i
STA name1, d

.ASCII "What is your middle name?"
LDA ?, i
STA name2, d

.ASCII "What is your last name?"
LDA ?, i
STA name3, d

.ASCII "What are you studying for school?"
LDA ?, i
STA major, d

.ASCII "Your Information:"

??Print name1, name2, name3, major??
STOP
.END

but I am hitting a wall with storing human input. So I took the easy route and just did CHARO over an over, but this seems like the wrong path... any ideas?

CHARO 0x44,i
CHARO 0x61,i
CHARO 0x6c,i
CHARO 0x61,i
CHARO 0x6c,i

CHARO 0x20,i

STOP
.END

*output is "Dalal "
 
Physics news on Phys.org
  • #2
angeliKITTYx said:

Homework Statement


You are to write a program that will display your full name and your major (First Name, Middle name and Last Name) on the Terminal Input/output (I/O) screen.[/B]

Homework Equations

The Attempt at a Solution


I was trying to get the screen to say "What's your first name?" *store human input as name1*
"Middle name? *store input as name2* etc... and then it would print the full name and my major at the end,

BR main

name1: .WORD ? (or do I use .BYTE ?)
name2: .WORD ?
name3: .WORD ?
major: .WORD ?

main: .ASCII "What is your first name?"
LDA ?, i
STA name1, d

.ASCII "What is your middle name?"
LDA ?, i
STA name2, d

.ASCII "What is your last name?"
LDA ?, i
STA name3, d

.ASCII "What are you studying for school?"
LDA ?, i
STA major, d

.ASCII "Your Information:"

??Print name1, name2, name3, major??
STOP
.END

but I am hitting a wall with storing human input. So I took the easy route and just did CHARO over an over, but this seems like the wrong path... any ideas?

CHARO 0x44,i
CHARO 0x61,i
CHARO 0x6c,i
CHARO 0x61,i
CHARO 0x6c,i

CHARO 0x20,i

STOP
.END

*output is "Dalal "
Caveat: I know very little about PEP/8 programming, but I know quite a bit about assembly programming in several languages.

Here are some things that I believe you're doing wrong.
1. name1, name2, name3, and major should not be .WORD. That type is used for integer (two-byte) values, not for strings of characters. For each of these I think you should be allocating a .BLOCK of memory, as in name1: .BLOCK 10
2. Each of your ASCII strings should be zero-terminated, like so: .ASCII "What is your first name? + \x00"

There is a string output instruction (STRO), but as far as I can tell, there's no string input instruction, so it looks like you'll need to have a loop to process each character and store it in the right location. For the first name, the loop should input a character and check that it isn't the space character. If it's not a space store it in the first cell of the memory block. The second iteration of the loop should store the second character in its location, and so on. If any loop iteration encounters a space character, branch out of the loop.
Do the same thing for the middle name, the last name, and the major.

A link that might be of help to you is http://www.cslab.pepperdine.edu/warford/cosc330/PDFChap05.pdf
 
Last edited by a moderator:
  • #3
Mark44 said:
Caveat: I know very little about PEP/8 programming, but I know quite a bit about assembly programming in several languages.

Here are some things that I believe you're doing wrong.
1. name1, name2, name3, and major should not be .WORD. That type is used for integer (two-byte) values, not for strings of characters. For each of these I think you should be allocating a .BLOCK of memory, as in name1: .BLOCK 10
2. Each of your ASCII strings should be zero-terminated, like so: .ASCII "What is your first name? + \x00"

There is a string output instruction (STRO), but as far as I can tell, there's no string input instruction, so it looks like you'll need to have a loop to process each character and store it in the right location. For the first name, the loop should input a character and check that it isn't the space character. If it's not a space store it in the first cell of the memory block. The second iteration of the loop should store the second character in its location, and so on. If any loop iteration encounters a space character, branch out of the loop.
Do the same thing for the middle name, the last name, and the major.

A link that might be of help to you is http://www.cslab.pepperdine.edu/warford/cosc330/PDFChap05.pdf
Thanks! But I'm having a hard time understanding the "0x0000, 0x0010, etc" stuff after the commands (CHARO, STRO, ADDA, etc) What is that? I'm understanding it as the location in the memory, but I'm just completely lost!
 
Last edited by a moderator:
  • #4
OK, I can answer that. Those are addresses relative to the start of your program, so if you have a .BLOCK directive at the start of your program, then CHARO 0x0000, d would output the first character in that block of bytes. If you have your data block elsewhere in your program, you'll have to count the number of bytes there are up to that block. Take a look at the link I sent, figure 5.9 (http://www.cslab.pepperdine.edu/warford/cosc330/PDFChap05.pdf ). Look at the assembler output, since it is laid out with all of the addresses of the code and data. In that example, he inputs two characters, and then outputs them. The first byte of the data block begins at byte 0x0D.
 
Last edited by a moderator:
  • #5
As far as ADDA goes, here are a couple lines of code from the same source, fig. 5.7
Code:
LDA 0x0011, d
ADDA  0x0013, d
The first instruction loads the number (a two-byte integer, I believe) that is at offset 0x0011, and stores it in the A (for accumulator) register. The next instruction adds the number (again, a two-byte integer) to what's in the A register.The rest of the code (that I don't show) does some arithmetic to convert the decimal number to an ASCII character for the number, and displays it.

I haven't found much documentation for PEP/8, and what I have found leaves it what I consider to me important information, such as samples of each instruction and what they do.
 
  • #6
Mark44 said:
OK, I can answer that. Those are addresses relative to the start of your program, so if you have a .BLOCK directive at the start of your program, then CHARO 0x0000, d would output the first character in that block of bytes. If you have your data block elsewhere in your program, you'll have to count the number of bytes there are up to that block. Take a look at the link I sent, figure 5.9 (http://www.cslab.pepperdine.edu/warford/cosc330/PDFChap05.pdf ). Look at the assembler output, since it is laid out with all of the addresses of the code and data. In that example, he inputs two characters, and then outputs them. The first byte of the data block begins at byte 0x0D.
Here's what I ended up doing, which answers the question:
BR main

name1: .ASCII "FULL NAME: \x00"
name2: .ASCII "mY nAmE \x00"
major1: .ASCII "MAJOR: \x00"
major2: .ASCII "Sciences \x00"

main: STRO name1, d
STRO name2, d
STRO major1, d
STRO major2, d

STOP

.END
HOWEVER, in the homework, the teacher puts in the help:
"You can use these boxes *shows screen clip* to determine the ASCII characters in your name."

Is there a way to do this program while using the hex or binary code instead of .ASCII? I technically answered the question, but I feel like that hint is saying I need to use them...
 
Last edited by a moderator:
  • #7
angeliKITTYx said:
Here's what I ended up doing, which answers the question:
BR main

name1: .ASCII "FULL NAME: \x00"
name2: .ASCII "mY nAmE \x00"
major1: .ASCII "MAJOR: \x00"
major2: .ASCII "Sciences \x00"

main: STRO name1, d
STRO name2, d
STRO major1, d
STRO major2, d

STOP

.END
HOWEVER, in the homework, the teacher puts in the help:
"You can use these boxes *shows screen clip* to determine the ASCII characters in your name."

Is there a way to do this program while using the hex or binary code instead of .ASCII? I technically answered the question, but I feel like that hint is saying I need to use them...
Answering myself... I tried this earlier, but it just seems like the cheap way!
CHARO 0x004d,i ;Output "M"
CHARO 0x0041,i ;Output "A"
CHARO 0x004a,i ;Output "J"
CHARO 0x004f,i ;Output "O"
CHARO 0x0052,i ;Output "R"
CHARO 0x003a,i ;Output ":"
CHARO 0x0020,i ;Output " "

CHARO 0x0053,i ;Output "S"
CHARO 0x0063,i ;Output "c"
CHARO 0x0069,i ;Output "i"
CHARO 0x0065,i ;Output "e"
CHARO 0x006e,i ;Output "n"
CHARO 0x0063,i ;Output "c"
CHARO 0x0065,i ;Output "e"
CHARO 0x0073,i ;Output "s"​
 
  • #8
Based on the problem as you stated it...,
angeliKITTYx said:

Homework Statement


You are to write a program that will display your full name and your major (First Name, Middle name and Last Name) on the Terminal Input/output (I/O) screen.
... I think either of the approaches you showed is valid. The problem description does not ask you to prompt for the strings, or to input from the keyboard, which is probably too complicated for where you currently are in the class.

Of your two approaches, I like your first one better, where you output each string using STRO.

The Attempt at a Solution


I was trying to get the screen to say "What's your first name?" *store human input as name1*
"Middle name? *store input as name2* etc... and then it would print the full name and my major at the end,[/QUOTE]
I gave a rough outline of how I would do it in post #2, but if you haven't been exposed to writing loops yet, you probably wouldn't be able to do it.
 

Related to Write PEP8 Code: Display Full Name & Major

1. What is PEP8 code?

PEP8 is a style guide for writing Python code that provides guidelines for formatting, naming conventions, and best practices. It helps improve code readability and maintainability.

2. Why is it important to follow PEP8 guidelines?

Following PEP8 guidelines ensures that your code is consistent, readable, and easy to understand for other developers. It also helps prevent potential errors and makes it easier to maintain and update your code in the future.

3. How do I display a full name and major using PEP8 code?

To display a full name and major using PEP8 code, you can use the str.format() method to insert variables into a string. For example, you can use "My name is {} and my major is {}" .format(name, major) to display the full name and major.

4. Are there any exceptions or special cases when writing PEP8 code for displaying a full name and major?

Yes, there are a few exceptions to consider when writing PEP8 code for displaying a full name and major. For example, if the name or major contains special characters or symbols, you may need to use escape sequences or the repr() function to properly format the output.

5. Can I use PEP8 code for other programming languages?

No, PEP8 is specific to Python and cannot be directly applied to other programming languages. However, many other languages have their own style guides that provide similar guidelines for writing clean and readable code.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
7K
  • Programming and Computer Science
Replies
7
Views
6K
  • Programming and Computer Science
Replies
5
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Programming and Computer Science
Replies
2
Views
3K
Back
Top