1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Writing a PEP8 code

  1. Mar 3, 2015 #1
    1. The problem statement, all variables and given/known data
    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.


    2. Relevant equations


    3. 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 "
     
  2. jcsd
  3. Mar 4, 2015 #2

    Mark44

    Staff: Mentor

    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: May 7, 2017
  4. Mar 4, 2015 #3

    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: May 7, 2017
  5. Mar 4, 2015 #4

    Mark44

    Staff: Mentor

    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: May 7, 2017
  6. Mar 4, 2015 #5

    Mark44

    Staff: Mentor

    As far as ADDA goes, here are a couple lines of code from the same source, fig. 5.7
    Code (Text):
    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.
     
  7. Mar 4, 2015 #6
    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: May 7, 2017
  8. Mar 4, 2015 #7
    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"​
     
  9. Mar 4, 2015 #8

    Mark44

    Staff: Mentor

    Based on the problem as you stated it...,
    ... 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.
    3. 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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted