• Support PF! Buy your school textbooks, materials and every day products Here!

Need help understanding part of this assembly code

  • Thread starter leo255
  • Start date
  • #1
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,691
522
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.
 
  • Like
Likes leo255
  • #3
CWatters
Science Advisor
Homework Helper
Gold Member
10,529
2,295
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.
 

Related Threads on Need help understanding part of this assembly code

Replies
16
Views
7K
  • Last Post
Replies
3
Views
9K
  • Last Post
Replies
6
Views
2K
Replies
2
Views
13K
Replies
4
Views
646
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
2
Views
4K
Replies
10
Views
12K
Replies
6
Views
877
Replies
14
Views
4K
Top