p-2
2a
org 0000h
sjmp 30h
org 30h
mov r0,#51h ;r0 pointed to internal RAM loc 51h (LS byte of data1)
mov r1,#53h ;r1 pointed to internal RAM loc 53h (LSbyte of data2)
clr c
mov a,@r0 ;perform LS byte addition save the result at 62h location
add a,@r1
dec r0
dec r1
mov 62h,a
mov a,@r0 ;perform MS byte addition save the result at 61h loc
addc a,@r1
mov 61h,a
jnb 0D7h, skip ; JNB 0D7h,target is bit addressable instruction equivalent
to JNC instruction
mov 60h,#01h ; if carry is there after addition save carry at 60h loc
sjmp here
skip: mov 60h,#00h
here: sjmp here
end
2b
org 0000h
sjmp 30h
org 30h
mov r0,#51h ;r0 pointed to internal RAM loc 51h (LS byte of data1)
mov r1,#53h ;r1 pointed to internal RAM loc 53h (LS byte of data2)
clr c
mov a,@r0 ;perform LS byte subtraction save the result at 62h location
subb a,@r1
dec r0
dec r1
mov 62h,a
mov a,@r0 ;perform MS byte subtraction save the result at 61h loc
subb a,@r1
mov 61h,a
jnb 0d7h, skip ;JNB 0D7h,target is bit addressable instruction equivalent
to JNC instruction
mov 60h,#01h ; if borrow is there after subtraction save borrow at 60h loc
sjmp here
skip: mov 60h,#00h
here: sjmp here
end
2c
org 0000h
sjmp 30h
org 30h
mov a,51h ; get LS byte of multiplicand to A register
mov b,52h ; get multiplier to B register
mul ab ; multiply
mov 61h,b ; save MS byte of the result at 61h
mov 62h,a ; save LSB byte of the result at 62h(LSB of result)
mov a,50h ; get MS byte of the multiplicand to A register
mov b,52h ; get multiplier to B register
mul ab ; multiply
add a,61h ; after multiplication add contents of A register to 61h
mov 61h,a ; save MSB1 of the result at 61h
mov a,0f0h
addc a,#00h
mov 60h,a ; save MSB2 of the result at 60h
sjmp $
end
2d
org 0000h
sjmp 30h
org 30h
mov r0,#51h ; LSByte of 16 bit dividend,
mov r1,#52h ; 8bit divisor is stored
mov dptr,#0000h ;initialize DPTR reg.=0000h for quotient
clr c
repeat: mov a,@r0 ; get lower byte of dividend
subb a,@r1 ;subtract divisor from dividend
mov @r0,a ; save result at 51hand 50h
dec r0
mov a,@r0
subb a,#00h
mov @r0,a
inc r0
jc last ;after every subtraction check if borrow flag is set
inc dptr ;after every sub increment dptr (quotient-no. of subtraction)
sjmp repeat
last: mov a,@r0 ; if borrow flag is set, add divisor to result to get remainder
add a,@r1
mov 63h,a ; save LSB of remainder at 63h
dec r0
mov a,@r0
addc a,#00h ;save MSB of remainder at 62h
mov 62h,a
mov 61h,dpl ; save LSB of quotient at 61h
mov 60h,dph ; save MSB of quotient at 60h
sjmp $
end
2e
org 000h
sjmp 30h
org 30h
mov a,50h ;get multiplicand to A register
mov b,50h ;get multiplier to A register
mul ab ; multiply (square)
mov 61h,a ;store lower byte of square of a number in higher address
mov 60h,b ;store higher byte of square of a number in lower address
mov b,50h
mul ab
mov 64h,a ;store lower byte of cube in higher address
mov 63h,b
mov b,50h
mov a,60h
mul ab
add a,63h
mov 63h,a
mov a,b
addc a,#00h
mov 62h,a ;store higher byte of cube in lower address
sjmp $
end
Comments
Post a Comment