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!

Need help understanding part of this assembly code

  1. Dec 8, 2014 #1
    CHARI 0xFE,d ; read 1stchar
    CHARI 0xFF,d ; read 2ndchar
    LDBYTEA 0xFE,d ; load 1stchar
    ADDA 0xFE,d ; add 2ndchar to low byte(big endian!)
    ANDA 0x0F,i ; keep low 4 bits
    ORA 0x30,i ; convert to ascii
    STBYTEA 0xFD,d ; store for output
    CHARO 0xFD,d ; write result
    STOP.END

    Hello, I mostly understand this assembly code, but am confused with this line: "ANDA 0x0F,i".

    This program inputs two single-digit numbers, adds them and then outputs their single-digit sum. Apparently, we are keeping the low 4 bits. What exactly is meant by this, specifically with what the program is trying to accomplish?
     
  2. jcsd
  3. Dec 8, 2014 #2

    rcgldr

    User Avatar
    Homework Helper

    For the AND operation, each bit that is zero in the 0x0f is zeroed in the result and each bit that is one in the 0xf is left the same as it was before (or copied if the result register is different than the source register), assuming that ANDA 0xf,i means to AND the accumulator with the immediate value 0x0f and store the result back into the accumulator.
     
  4. Dec 10, 2014 #3

    CWatters

    User Avatar
    Science Advisor
    Homework Helper

    Suppose the result of the addition is
    00101010
    if you AND that with
    00001111
    you get
    00001010

    The four most significant bits have been suppressed to zero leaving just the four least significant bits from the sum.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Need help understanding part of this assembly code
Loading...