Sunteți pe pagina 1din 5

04/11/2015

BILKENT UNIVERSITY
EEE 212 Microprocessors

Midterm
Closed TextBook, Closed Notes, No Calculators
Use the boxes provided for your answers!
Use comments for readability,
otherwise theprograms will be partially graded!
Duration: 120 minutes

Surname:____________________________________

Name:______________________________________

ID-Number:__________________________________

Signature:___________________________________

Q1 (16 points)

Q2 (20 points)

Q3 (30 points)

Q4 (34 points)

TOTAL
Q1) (16 points) Find the values of the registers below after each specified instruction. (The
initial value of register SP is 07.)

ORG 0
MOV R7, #5Ch
MOV R2, #29h
MOV A, R7
XRL A, #0FFh ; A = ___A3___h
MOV R1, #7
XCH A, @R1 ; A = ___5C___h
PUSH 7
POP 0F0h ; B = ___A3___h (Hint: Byte address of B is F0h)
SETB C
CLR A
ADDC A, 2 ; A = ___2A___h
MOV A, #1Dh
SWAP A
ORL A, #3Ch ; A = ___FD___h
MOV 33h, #91h
PUSH 33h
MOV A, SP ; A = ___08___h
POP 20h
MOV R6, #0
JNB 4, NEXT
INC R6
NEXT: MOV A, R6 ; A = ___01___h
CJNE A, #1, CONT
INC R6
CONT: MOV A, R6
SWAP A
JB ACC.7, THERE
INC R6
THERE: CLR A ; R6 = ___03___h
END
Q2) (20 points) There exist some bytes in the internal ROM space from address 0200h to
address 0231h. Each pair of consecutive bytes forms a two-byte number (unsigned). For
example, if the addresses 0200h, 0201h, 0202h, 0203h, 0204h, 0205h,..., 0230h, 0231h contain
52h, 3Ah, 37h, 00h, 8Bh, 09h,..., 16h, 28h, respectively; then, the two-byte numbers are 523Ah,
3700h, 8B09h,..., 1628h.
Complete the following subroutine in order to determine how many of the two-byte numbers
are integer multiples of 8 (i.e., divisible by 8). The following rules must be considered in the
solution:
- The result should be saved in register R2.
- No more than 15 instructions can be used.
- DB directive cannot be used (i.e., no look-up tables).

SUBRT_Q2:
MOV R2, #0
MOV DPTR, #0200h
MOV R3, #25
REPEAT: CLR A
INC DPTR
MOVC A, @A+DPTR
ANL A, #0Fh
JZ INCRE
CJNE A, #8, NOINC
INCRE: INC R2
NOINC: INC DPTR
DJNZ R3, REPEAT

RET
Q3) (30 points) Suppose that there are 30 bytes in the packed BCD format in the internal RAM
locations starting from byte address 32h. Complete the following program to
(a) determine how many of these packed BCD numbers are squares of integers (for example, 25h
in the packed BCD format corresponds to 25, which is the square of 5; hence, we should count
25h.)
(b) for each BCD number that is a square of an integer, send the square root of that number of
port 2 (P2).
You must use a look-up table approach as specified below and not use more than 20 instructions.

SQURS: MOV DPTR, #LOOKUP


MOV R5, #0 ; number of squares
MOV R0, #32h ; initial RAM address
MOV R4, #30 ; number of bytes
NEXT: MOV B, @R0 ;
INC R0 ;
MOV R2, #10 ;
;
MOV R3, #0 ;
REPEAT: MOV A, R3 ;
MOVC A, @A+DPTR ;
CJNE A, B, NOTEQ
INC R5 ;
MOV P2, R3 ;
SJMP THERE ;
NOTEQ: INC R3 ;
DJNZ R2, REPEAT ;
;
THERE: DJNZ R4, NEXT ;
;
;
;
;
EXIT: RET
LOOKUP: DB 00, 01, 04, 09, 16h, 25h, 36h, 49h, 64h, 81h ; please write all
; the entries here
Q4) (34 points) Assume that Port 1 has the connections as shown in the figure. For the following
assembly language program, determine the contents of the RAM given below just before the
execution of SJMP $. (Note that empty locations will be assumed to be 00h before the program is
run.)

ORG 0
SETB PSW.4
MOV R1, #39h
MOV R5, #2Eh
MOV R6, #0B1h
MOV P1, #0FFh
MOV A, P1
SUBB A, #12h
MOV C, ACC.2
MOV 7Eh, C
JNC NEXT
SWAP A
NEXT:
MOV 41h, A
PUSH 17
PUSH 41h
MOV C, P1.0
MOV 9, C
MOV 18h, @R1
MOV R0, #19h
MOV @R0, #53h
LJMP THERE
ORG 0411h
THERE:
LCALL SUBRTNE
INC @R0
MOV 4, 19h
SJMP $
SUBRTNE:
PUSH 16h
POP 61h
MOV R3, 61h
RET
END

S-ar putea să vă placă și