- #1
Mastur
- 41
- 0
Homework Statement
Create a Menu to run a program for LED sequences using procedure calls or macros as follows: [1] Blinking LED [2] Two at a time [3] Alternate [4] Rotate Right [5] Rotate Left . The program will display „1‟ for LED “ON” and „0‟ for LED “OFF”. Use delay, message output and clear screen procedures within your program. Blinking is just a subroutine. Message output is answerable by Yes or No whether to go back to the main MENU or repeat the sequence.
Homework Equations
How do I display the value in register AX (in binary form)?
How do I perform long jumps?
The Attempt at a Solution
I'm done with 1, 2 and 3 but what I did are just string declarations so that I can call them later in the code. But that will make the program really long. With that, an error will occur, saying "Relative jump out of range by x bytes." I tried long jump but it does not work (call ptr far procedure_name) How do I resolve this? Anyway, here's the code I created.
Code:
.model small
.stack 64
.data
options1 db "[A] Blinking",10,13
db "[B] Alternating",10,13
db "[C] 2 at a time",10,13
db "[D] -2 at a time",10,13
db "[E] Rotate Left",10,13
db "[F] Rotate Right",10,13
db "[G] Quit",10,13,'$'
nolight db "0000 0000",10,13,'$'
light db "1111 1111",10,13,'$'
alter1 db "0101 0101",10,13,'$'
alter2 db "1010 1010",10,13,'$'
twoattime1 db "0000 0011",10,13,'$'
twoattime2 db "0000 1100",10,13,'$'
twoattime3 db "0011 0000",10,13,'$'
twoattime4 db "1100 0000",10,13,'$'
.code
main proc far
mov ax,@data
mov ds,ax;-------------------------
mov ah,09h
mov dx,offset options1
int 21h
mov ah,01h
int 21h
cmp al,41h
je BLINKING
cmp al,42h
je alternate
cmp al,43h
je POS2ATTIME
cmp al,44h
je NEG2ATTIME
jne exitProgram
BLINKING:
call clearscreen
mov ax,@data
mov ds,ax
mov ah,09h
mov dx,offset nolight
int 21h
call delay
call clearscreen
mov dx,offset light
int 21h
call delay
loop BLINKING
alternate:
call clearscreen
mov ax,@data
mov ds,ax
mov ah,09h
mov dx,offset alter1
int 21h
call delay
call clearscreen
mov dx,offset alter2
int 21h
call delay
loop alternate
POS2ATTIME:
call clearscreen
mov ah,09h
mov dx,offset twoattime1
int 21h
call delay
call clearscreen
mov dx,offset twoattime2
int 21h
call delay
call clearscreen
mov dx,offset twoattime3
int 21h
call delay
call clearscreen
mov dx,offset twoattime4
int 21h
call delay
loop POS2ATTIME
NEG2ATTIME:
call clearscreen
mov ah,09h
mov dx,offset twoattime4
int 21h
call delay
call clearscreen
mov dx,offset twoattime3
int 21h
call delay
call clearscreen
mov dx,offset twoattime2
int 21h
call delay
call clearscreen
mov dx,offset twoattime1
int 21h
call delay
loop NEG2ATTIME
;------------------------
exitProgram:
mov ah,4ch
int 21h
main endp
clearscreen proc
push ax
mov ax,0600h
mov bh,07
mov cx,0000
mov dx,184fh
int 10h
mov ah,02h
mov bh,00
mov dx,0000h
int 10h
pop ax
ret
clearscreen endp
delay proc
push ax
mov cx,0fffh
delay2:
push cx
mov cx,0ffffh
delay3:
nop
nop
nop
nop
nop
loop delay3
pop cx
loop delay2
pop ax
ret
delay endp
end main