Writing a PEP8 code

  • #1

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 "
 

Answers and Replies

  • #2
35,428
7,287

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 [Broken]
 
Last edited by a moderator:
  • #3
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 [Broken]


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
35,428
7,287
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 [Broken]). 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
35,428
7,287
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
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 [Broken]). 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
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
35,428
7,287
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 Threads on Writing a PEP8 code

Replies
2
Views
13K
  • Last Post
Replies
3
Views
10K
Replies
16
Views
8K
  • Last Post
Replies
1
Views
2K
Replies
2
Views
796
Replies
4
Views
854
Replies
4
Views
8K
Replies
14
Views
4K
Replies
10
Views
12K
  • Last Post
Replies
1
Views
4K
Top