231a-ag Lab6

From CSclasswiki
Jump to: navigation, search

Lab 6

Assembly Part on the PC

Outputting Information

LedOn

You are going to create a program called ledOn that turns on the LED connected to Pin 13.

;;;          ____        _                                                          
;;;         |  _ \  __ _| |_ __ _                                                   
;;;         | | | |/ _` | __/ _` |                                                  
;;;         | |_| | (_| | || (_| |                                                  
;;;         |____/ \__,_|\__\__,_|                                                  
;;;                                                                                 


          section        .data
errorMsg  db     "Error accessing file!",0x0a, 0
errorMsg1 db     "Error opening file!",0x0a, 0
usb       db     "/dev/ttyUSB0",0
handle    dd     0
noRead    dd     0
msg       db     "w d 13 1", 0x0d
msgLen    equ    $-msg

          section .bss
%assign   MAXBUF  100
buffer    resb    MAXBUF

;;;           ____          _                                                       
;;;          / ___|___   __| | ___                                                  
;;;         | |   / _ \ / _` |/ _ \                                                 
;;;         | |__| (_) | (_| |  __/                                                 
;;;          \____\___/ \__,_|\___|                                                 
;;;                                                                                 


        section .text

global  asm_main
asm_main:

;;; open file, write string, close file...             

        mov     ebx, usb
        call    openFile
        mov     dword[handle], eax
        mov     ebx, [handle]
        mov     ecx, msg
	mov     edx, msgLen
        call    writeFile
        mov     ebx, dword[handle]
        call    closeFile

;;; we're done!                                                                     

exit:
        mov     eax,EXIT
        mov     ebx,0
        int     0x80             ; final system call                                

Does the LED on Pin 13 turn ON? (If your Pin 13 is damaged from previous labs, please put a resistor plus LED connected to Pin 11).

  • Yes, the LED on Pin 13 turns on.

LedOff

Make a copy of ledOn.asm under the name ledOff.asm, modify it, and compile it. Use it to turn OFF the LED.

;;;          ____        _                                                           
;;;         |  _ \  __ _| |_ __ _                                                    
;;;         | | | |/ _` | __/ _` |                                                   
;;;         | |_| | (_| | || (_| |                                                   
;;;         |____/ \__,_|\__\__,_|                                                   
;;;                                                                                  


          section        .data
errorMsg  db     "Error accessing file!",0x0a, 0
errorMsg1 db     "Error opening file!",0x0a, 0
usb       db     "/dev/ttyUSB0",0
handle    dd     0
noRead    dd     0
msg       db     "w d 13 0", 0x0d
msgLen    equ    $-msg

          section .bss
%assign   MAXBUF  100
buffer    resb    MAXBUF

;;;           ____          _                                                        
;;;          / ___|___   __| | ___                                                   
;;;         | |   / _ \ / _` |/ _ \                                                  
;;;         | |__| (_) | (_| |  __/                                                  
;;;          \____\___/ \__,_|\___|                                                  
;;;                                                                                  


        section .text

global  asm_main
asm_main:

;;; open file, write string, close file...                                           

        mov     ebx, usb
        call    openFile
        mov     dword[handle], eax
        mov     ebx, [handle]
        mov     ecx, msg
        mov     edx, msgLen
        call    writeFile
        mov     ebx, dword[handle]
        call    closeFile

;;; we're done!                                                                      

exit:
        mov     eax,EXIT
        mov     ebx,0
        int     0x80             ; final system call                                 

LedOnOff

Same scenario, but now this time make your assembly program send an ON message, followed by an OFF message in an endless loop.

;;;          ____        _                                                           
;;;         |  _ \  __ _| |_ __ _                                                    
;;;         | | | |/ _` | __/ _` |                                                   
;;;         | |_| | (_| | || (_| |                                                   
;;;         |____/ \__,_|\__\__,_|                                                   
;;;                                                                                  


          section        .data
errorMsg  db     "Error accessing file!",0x0a, 0
errorMsg1 db     "Error opening file!",0x0a, 0
usb       db     "/dev/ttyUSB0",0
handle    dd     0
noRead    dd     0
msg       db     "w d 13 1", 0x0d
msgLen    equ    $-msg
msg2      db     "w d 13 0", 0x0d
msg2Len   equ    $-msg2

          section .bss
%assign   MAXBUF  100
buffer    resb    MAXBUF

;;;           ____          _                                                        
;;;          / ___|___   __| | ___                                                   
;;;         | |   / _ \ / _` |/ _ \                                                  
;;;         | |__| (_) | (_| |  __/                                                  
;;;          \____\___/ \__,_|\___|                                                  
;;;                                             


        section .text

global  asm_main
asm_main:

;;; open file, write string, close file...                                           


forl33t:
        mov     ebx, usb
        call    openFile
        mov     dword[handle], eax
        mov     ebx, [handle]
        mov     ecx, msg
        mov     edx, msgLen
        call    writeFile
        mov     ebx, dword[handle]
        call    closeFile

        call    delayhappy

        mov     ebx, usb
        call    openFile
        mov     dword[handle], eax
        mov     ebx, [handle]
        mov     ecx, msg2
        mov     edx, msg2Len
        call    writeFile
        mov     ebx, dword[handle]
        call    closeFile

        call    delayhappy
        jmp     forl33t

delayhappy:
        mov     ecx,0
delayloop:
        loop delayloop
        ret

Measure the frequency of the LED turning ON and OFF. This will give us an idea of how fast we can activate devices attached to the Arduino.