Codice Assembly per Sistema di Controllo Semaforo (8086)
Di seguito è riportato un esempio di codice assembly per l'architettura 8086 che implementa un semplice sistema di controllo semaforo con gli stati rosso, giallo e verde.
; Define memory addresses for traffic light control
TL_RED equ 00H
TL_YELLOW equ 01H
TL_GREEN equ 02H
TL_CONTROL equ 03H
; Define I/O ports
OUTPUT_PORT equ 04H
; Delay constant
DELAY_TIME equ 10000
org 100H
main:
mov al, TL_RED
mov [TL_CONTROL], al
jmp loop
loop:
mov al, [TL_CONTROL]
cmp al, TL_RED
je red
cmp al, TL_YELLOW
je yellow
cmp al, TL_GREEN
je green
red:
mov al, OUTPUT_PORT
out al, 01H
call delay
mov al, OUTPUT_PORT
out al, 00H
mov al, TL_YELLOW
mov [TL_CONTROL], al
jmp loop
yellow:
mov al, OUTPUT_PORT
out al, 01H
call delay
mov al, OUTPUT_PORT
out al, 00H
mov al, TL_GREEN
mov [TL_CONTROL], al
jmp loop
green:
mov al, OUTPUT_PORT
out al, 01H
call delay
mov al, OUTPUT_PORT
out al, 00H
mov al, TL_RED
mov [TL_CONTROL], al
jmp loop
delay:
mov cx, DELAY_TIME
xor dx, dx
delay_loop:
loop delay_loop
ret