1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Different LED displays (Assembly)

  1. Aug 17, 2012 #1
    1. The problem statement, all variables and given/known data
    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.
    2. Relevant equations
    How do I display the value in register AX (in binary form)?
    How do I perform long jumps?
    3. 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 (Text):
    .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
     
     
  2. jcsd
  3. Aug 17, 2012 #2

    rcgldr

    User Avatar
    Homework Helper

    That last jne can be a jmp:

    Code (Text):

            cmp     al,44h
            je      NEG2ATTIME
            jmp     exitProgram
     
    Also after doing the loop for "blinking", the processor is going to drop into the code for "alternate", you probably want the code to go to exitProgram after each of those loops.
     
    Last edited: Aug 17, 2012
  4. Aug 18, 2012 #3
    Our professor said that its fine if the program can be executed only once, as long as all the routines are working.

    By the way, the problem remains the same.
     
  5. Aug 18, 2012 #4

    rcgldr

    User Avatar
    Homework Helper

    That isn't the issue, the problem is that if blinking is chosen, then the code will do all the other patterns as well.

    Try using nearby jump points for the short conditional jumps. For the other problem, add jumps to exitProgram after each loop:

    Code (Text):

    ; ...
    cmp al,41h
    je BLINKING0
    cmp al,42h
    je alternate0
    cmp al,43h
    je POS2ATTIME0
    cmp al,44h
    je NEG2ATTIME0
    jmp exitProgram

    BLINKING0:
    jmp BLINKING

    alternate0:
    jmp alternate

    POS2ATTIME0:
    jmp POS2ATTIME

    NEG2ATTIME0:
    jmp NEG2ATTIME

    BLINKING:
    ; ...
    loop BLINKING

    jmp exitProgram ; jump to exitProgram
                    ;instead of falling into alternate

    alternate:
    ; ...
     
     
  6. Aug 18, 2012 #5
    OK, OK, sorry I misinterpreted what you've said. The only display is a black screen with my desired input and nothing at all. (Or that's not what you're pointing out?)

    Anyway, I was able to resolve the problem already (The relative jump problem). Next thing to do is to display the message output (Menu) even if I already chosen the LED display. How do I do that?
     
    Last edited: Aug 18, 2012
  7. Aug 19, 2012 #6

    rcgldr

    User Avatar
    Homework Helper

    I see a clearscreen function, but I don't see a function to display something on the screen.
     
  8. Aug 19, 2012 #7
    I tried calling the displaymenu function (from my new code) inside the BLINKING loop but it stops displaying the menu, unless I choose another display. Has it something to do with the int 01h function?

    Code (Text):
    .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 "[Other Keys] 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,'$'

    rotate1 db "0000 0001",10,13,'$'
    rotate2 db "0000 0010",10,13,'$'
    rotate3 db "0000 0100",10,13,'$'
    rotate4 db "0000 1000",10,13,'$'
    rotate5 db "0001 0000",10,13,'$'
    rotate6 db "0010 0000",10,13,'$'
    rotate7 db "0100 0000",10,13,'$'
    rotate8 db "1000 0000",10,13,'$'

    .code
    main proc far
    mov ax,@data
    mov ds,ax;-------------------------
    call displaymenu
    ;------------------------
    exitProgram:
    mov ah,4ch
    int 21h
    main endp

    displaymenu proc
    disp:
    mov ah,09h
    mov dx,offset options1
    int 21h

    mov ah,01h
    int 21h

    cmp al,41h
    je BLINKING1

    cmp al,42h
    je ALTERNATE1

    cmp al,43h
    je POS2ATTIME1

    cmp al,44h
    je NEG2ATTIME1

    cmp al,45h
    je ROTL1

    cmp al,46h
    je ROTR1

    jmp exitProgram

    BLINKING1: call BLINK
    ALTERNATE1: call ALTER
    POS2ATTIME1: call POS2
    NEG2ATTIME1: call NEG2
    ROTL1: call ROTATELEFT
    ROTR1: call ROTATERIGHT
    loop disp
    displaymenu 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

    BLINK proc
    BLINKING:
    call clearscreen
    call displaymenu
    mov ax,@data
    mov ds,ax
    mov ah,09h
    mov dx,offset nolight
    int 21h
    call delay
    call clearscreen
    call displaymenu
    mov dx,offset light
    int 21h
    call delay
    loop BLINKING
    BLINK endp

    ALTER proc
    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
    ALTER endp

    POS2 proc
    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
    POS2 endp

    NEG2 proc
    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
    NEG2 endp

    ROTATELEFT proc
    ROTL:
    call clearscreen
    mov ah,09h
    mov dx,offset rotate8
    int 21h
    call delay
    call clearscreen
    mov dx,offset rotate7
    int 21h
    call delay
    call clearscreen
    mov dx,offset rotate6
    int 21h
    call delay
    call clearscreen
    mov dx,offset rotate5
    int 21h
    call delay
    call clearscreen
    mov dx,offset rotate4
    int 21h
    call delay
    call clearscreen
    mov dx,offset rotate3
    int 21h
    call delay
    call clearscreen
    mov dx,offset rotate2
    int 21h
    call delay
    call clearscreen
    mov dx,offset rotate1
    int 21h
    call delay
    loop ROTL
    ROTATELEFT endp

    ROTATERIGHT proc
    ROTR:
    call clearscreen
    mov ah,09h
    mov dx,offset rotate1
    int 21h
    call delay
    call clearscreen
    mov dx,offset rotate2
    int 21h
    call delay
    call clearscreen
    mov dx,offset rotate3
    int 21h
    call delay
    call clearscreen
    mov dx,offset rotate4
    int 21h
    call delay
    call clearscreen
    mov dx,offset rotate5
    int 21h
    call delay
    call clearscreen
    mov dx,offset rotate6
    int 21h
    call delay
    call clearscreen
    mov dx,offset rotate7
    int 21h
    call delay
    call clearscreen
    mov dx,offset rotate8
    int 21h
    call delay
    loop ROTR
    ROTATERIGHT endp
    end main
     
    I'm sorry if it sounds like I'm asking for too much. Its just that I really do not understand everything taught to us unlike in other programming languages (high level).
     
    Last edited: Aug 19, 2012
  9. Aug 19, 2012 #8

    rcgldr

    User Avatar
    Homework Helper

    You need to find a reference for BIOS and MSDOS INT function descriptions. You can start with this wiki article:

    http://en.wikipedia.org/wiki/BIOS_interrupt_call

    The INT 10 (hex) are calls to the BIOS video driver. The INT 21 (hex) are calls to MSDOS. Normally AH contains the main parameter for the function to be performed. This will be explained in the links from the Wiki article above.

    You keep referring to LED, but normally a PC doesn't have a LED display. Is there some special hardware on the test system that has LEDs?
     
    Last edited: Aug 19, 2012
  10. Aug 20, 2012 #9
    I guess we're not having the same thought, or I am completely lost to what you are saying. I am sorry. >.<

    Well, yes, normally a PC does not have a LED display. The LED display I am referring is the string values I have declared in the .data, where 1 is an indicator that the LED is on and 0 otherwise.

    I am referring to the equivalent syntax in TASM for the Console.KeyPress in C#.

    Lets say I ran the program. Of course the menu from [A] - [G] will be displayed. And as I press Shift+A, the console will still be displaying menu and the alternating string values of 0000 0000 and 1111 1111. If I pressed again Shift+B, the menu will still retain, but the 0000 0000 and 1111 1111 displays will be replaced by 0101 0101 and 1010 1010.

    I tried checking the link you gave. As I read through that article, its either those has nothing to do with this or I just really do not understand what's the article all about. :\

    I also tried google'd about this so-called "subroutine" included in the instruction given to us. Unfortunately, I also do not understand those. :\
     
  11. Aug 20, 2012 #10

    rcgldr

    User Avatar
    Homework Helper

    For the INT 10 (video) functions, try looking at page 41 and 42 of this pdf file that was included as a link in the wiki article:

    bios_user_manual.pdf
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Different LED displays (Assembly)
  1. Assembly Language (Replies: 0)

  2. LED Animation >< (Replies: 1)

Loading...