Tuto 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Tutorial 2:

The 2nd tutorial is based on illustrating usage of arithmetic instructions such as INC, DEC,
ADD, ADDC, SUBB, MUL, DIV and DA A.
1. Add unsigned numbers from internal RAM locations 35h, 36h and 37h together and put the
result in RAM location 21h (MSB) & 20h(LSB)
2. Perform 16x16 unsigned multiplication where multiplicand X is in R1(MSB)R0 and
multiplier Y is in R3(MSB)R2 pair. Store final 32-bit result in R3 (MSB),R2,R1,R0

Ans 1:
mov A, 35H mov A, R0 ; get sum back
add A, 36H ; add first 2 bytes add A, 37H ; add 3rd number
mov R0, A ; save sum in R0 mov 20H, A ; store LSB of result
mov A, #00H ; clear A mov A, #00H ; clear A
addc A, 21H ; add carry to MSB addc A, 21H ; form final MSB
mov 21H, A ; save MSB of result mov 21H, A

Ans 2: At every stage of partial product (PP) generation we save lower and higher byte of
result in DPL and DPH respectively.
mov A, R0 mov A, DPH
mov B, R2 addc A, B ; get correct higher byte
mul AB ; multiply R2 x R0 (1st PP) mov DPH, A
mov DPL, B ; temp higher byte mov f0, C ; save intermediate carry
xch A, R0 ; store lower byte in R0 and mov A, R3
get back R0 in A mov B, R1
mov B, R3 mul AB ; multiply R1x R3 (4th PP)
nd
mul AB ; multiply R0 x R3 (2 PP) add A, DPH ;
add A, DPL mov R2, A
mov DPL, A ; save lower byte in DPL clr A
clr A addc A, B ;
addc A, B ; get correct higher byte mov C, f0 ; retrieve intermediate carry
mov DPH, A ; store higher byte in DPH addc A, #0
mov A, R2 mov R3, A
mov B, R1 mov R1, DPL
mul AB ; multiply R1xR2 (3rd PP)
add A, DPL
mov DPL, A ; save lower byte

You might also like