Computer Science
Branching and Looping
1.Watch videos entitled “Module 4 – Introduction” and “Module 4 – Branching and Looping”
2.Using the microprocessor simulator, open the program 02light.asm.
3.Step through its execution to understand its current operation.
4.Complete the table in the Ports section of the lab to determine the appropriate Hexadecimal values to use to control the traffic lights.
5.Modify the program to step the lights through a realistic sequence. Include conditional statements that ensure that assembly program only executes for 10 times.
6.Include all of the following in a Word document entitled “Lab4_StudentID”. Where your student id is substituted in the file name. a.A screenshot of the modified assembly code
b.The values of the Ports table to control the traffic lights
c.A few screenshots that show the traffic lights on Port 1 as the program is stepped through
7.Upload file “Lab4_StudentID”.
; _____ THE REALISTIC TRAFFIC LIGHTS _____________________________
CLO ; close unwanted windows
start:
MOV BL,10 ; Start BL register at 10
; Turn off all traffic lights
MOV AL,10 ; Copy 00000000 into the AL register
OUT 01 ; Send AL to port one
MOV BL,0A ; BL=TEN
LOOP:
; Turn red lights on
MOV AL,90 ; Copy 10010000 into the AL register
OUT 01 ; Send AL to port one
MOV AL,10 ; Delay
; Turn on amber lights
MOV AL,48 ; Copy 01001000 into the AL register
OUT 01 ; Send AL to port one
MOV AL,10 ; Delay
; Turn on green lights
MOV AL,24 ; Copy 00100100 into AL register
OUT 01 ; Send AL to port one
MOV AL,10 ; Delay
DEC BL ; Subtract one from BL
JNZ LOOP ; Jump back to loop if BL was not zero
END ; Program ends
; —– Time Delay Procedure Stored At Address [30] ————-
ORG 30 ; Generate machine code from address [30]
PUSH AL ; Save AL on the stack.
PUSHF ; Save the CPU flags on the stack.
Rep:
DEC AL ; Subtract one from AL.
JNZ REP ; Jump back to Rep if AL was not Zero.
POPF ; Restore the CPU flags from the stack.
POP AL ; Restore AL from the stack.
RET ; Return from the procedure.
; —————————————————————
END
; —————————————————————