Up Assignment#1 - Fall 2017
Up Assignment#1 - Fall 2017
Question#1:
a) Dry run the code given below and explain the complete working of the code.
b) If the subroutine “complement” is called using ACALL command then explain
whether the code will execute in the same manner or not. Give your answer with
proper reasoning.
org 0x000F
mov A,#0AH
acall double
here:
mov P1,A
sjmp here
double:
add A,0E0H
lcall complement
ret
org 0x2FFF
complement:
cpl A
mov P1,A
ret
end
Question#2:
a) Dry run the code if A=3H and find out the relative address for each jump.
b) Dry run the code if A=2H and find out the relative address for each jump.
National University of Computer & Emerging Sciences, Lahore
Department of Electrical Engineering (Fall 2017)
LOCATION CODE
org 0x0
0000 again:
0000 mov p1,a
0002 jnb acc.0,mul_2 //check 0th bit of accumulator is high
0005 mov b,#2
0008 mul ab
0009 mov b,#3
000C div ab
000D mov p2,a
000F sjmp again
0011 mul_2:
0011 mov b,#3
0014 mul ab
0015 mov b,#2
0018 div ab
0019 mov p2,b
End
Question#3:
Write a program that calculates the result of the number in register R0 raised to the power
the number stored in R1 register. For example, if R0=3 and R1=4, then your result will be
34 = 81. Show the 16-bit result in A (Lower Byte) and B (Upper Byte).
Question#4:
Write a program that finds a 2-byte square root of a number in A [0H - FH]. The first byte
is the integer value of the root, and the second byte is the fractional value of the root. Your
program should show the integer value (in decimal) in R5 and the fractional value (in
decimal) in R6. For example, square root of 2 is 1.41 approximately then your code should
show ‘01’ in R5 and ‘41’ decimal in R6.
Use lookup tables to store the corresponding integer and fractional value of square root of
a number.
Question#5:
Write an assembly language program that converts the hex number in accumulator A to an
equivalent BCD number in registers R6 (MSB digit) and R7 (LSB digit).
National University of Computer & Emerging Sciences, Lahore
Department of Electrical Engineering (Fall 2017)
Question#6:
Write a program that sets the P1.3 pin for 20msec every 100msec continuously. Assume
crystal frequency to be 24MHz.