UNIT 3:
LECTURE 16: ASSEMBLY LANGUAGE PROGRAMS:
8. WAP to find the square of the number in the range 0h to ffh
//Finds the square of the number in data RAM 20h and store the square in location30h and31h
org 0h
mov r0,#20H
mov a,@r0 ;num in 20h is loaded into acc and b reg mov 0f0h,a
mul ab
mov 030h,a ;lower order product in 30h
mov 031h,0f0h ;higher order product in 31h here: sjmp here
end
9. Program to convert BCD to ASCII
// The equivalent ASCII code will be found in Registers R2 and R6
10. WAP to find the cube of the number in the range 0h to fh//WAP to find the cube of the number in data RAM 20h and store the result in 30h
org 0h
mov r0,#20H
mov a,@r0 / ;num in 20h is loaded into acc and b reg
mov 0f0h,a
mul ab / ;find the square of the no.
mov 0f0h,@r0
mul ab / ;multiply square of the no. by the no.to get the cube.
mov 030h,a ;lower order product in 30h
mov 031h,0f0h / ;higher order product in 31h
here: sjmp here
end
11. WAP to convert BCD to ASCII
org 0h
start:mov r0,#20h mov a,@r0
add a,#30h mov 40h,a sjmp start end
12. WAP to convert given decimal no. to equivalent ASCII
org 0h
start:mov r0,#30h;r0 pointing to src locn.
mov a,@r0;acc. loaded with decimal no.
;process of seperating the lower nibble and higher nibble of decimal no.
anl a,#0fh;mask higher nibble
mov r1,a;lower nibble stored at r1
mov a,@r0
anl a,#0f0h;mask lower nibble
swap a;exchange higher and lower nibble positions
mov r2,a;higher nibble stored in r2
;process of converting decimal to ASCII
mov a,r1
add a,#30h
mov 40h,a;40h has ASCII value for lower nibble of decimal no.
mov a,r2
add a,#30h
mov 41h,a;41h has ASCII value for higher nibble of decimal no.
sjmp start
end
13. WAP to convert given hex no. to equivalent decimal no.
//Hex number has to be store at location x:5fffh and result to be stored in //next consecutive locations
org 0h
start:
mov dptr,#5fffh
movx a,@dptr
mov 0f0h,#064h;Load B reg with 100d or 64h
div ab;Hundreds
inc dptr
movx @dptr,a;store in external ram
mov a,0f0h;remainder from b reg to acc
mov 0f0h,#0ah; Load B reg with 10d or 0ah
div ab;
inc dptr;
movx @dptr,a;store tens in external ram
inc dptr
mov a,0f0h
movx @dptr,a;store units in ext ram
here:sjmp here
end
14. WAP to convert given decimal no. to equivalent hexadecimal no. org 0h
start:mov r0,#30h
mov a,@r0
;process of separating the lower nibble and higher nibble of decimal no.
anl a,#0fh / ;mask higher nibblemov r1,a / ;lower nibble stored at r1
mov a,@r0
swap a / ;exchange higher and lower nibble position
anl a,#0fh / ;mask lower nibble
mov r2,a / ;higher nibble stored in r2
mov a,r1;lower nibble to acc
mov 0f0h,#01h;reg b=01
mul ab
mov r3,a;product in r3
mov a,r2;higher nibble to acc
mov 0f0h,#0ah;reg b=10d
mul ab;product in acc.
add a,r3;compute hex no.
mov 40h,a;result at 40h
sjmp start
end