Need help understanding part of this assembly code

  • Thread starter leo255
  • Start date
  • #1
leo255
57
2
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?
 

Answers and Replies

  • #2
rcgldr
Homework Helper
8,791
579
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.
 
  • #3
CWatters
Science Advisor
Homework Helper
Gold Member
10,545
2,317
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.
 

Suggested for: Need help understanding part of this assembly code

Replies
20
Views
843
Replies
13
Views
467
  • Last Post
Replies
2
Views
1K
  • Last Post
Replies
2
Views
348
Replies
12
Views
738
  • Last Post
Replies
1
Views
135
Replies
2
Views
552
Replies
4
Views
1K
Replies
8
Views
219
Top