231a-ac Lab6

From CSclasswiki
Jump to: navigation, search

I collaborate with Lei Lei during this lab.

LedOn

  • In ledOn.asm, the message containing the command is defined in bytes inside the .data section, using the name msg. This message is later written to the usb file inside section asm_main.
  • LED on Pin 13 turns ON when we run the compiled program.

LedOff

To make Led on Pin 13 turn off, we simply change the last character of msg from 1 by 0. For example,

msg       db     "w d 13 0", 0x0d

LedOnOff

  • Here is our modified version of asm_main that makes Led 13 blink.
asm_main:

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


for:
        mov     ebx, usb
	call    openFile
        mov     dword[handle], eax
        mov     ebx, [handle]

	
        mov     ecx, msgOn	;led on
        mov     edx, onLen
        call    writeFile
        mov     ebx, dword[handle]
	call    closeFile
	

	push	ecx		;delay
	mov 	ecx,0
delay1:
	loop	delay1
	pop	ecx


	mov     ebx, usb
	call    openFile
        mov     dword[handle], eax
        mov     ebx, [handle]
	
	mov     ecx, msgOff	;led off
        mov     edx, offLen
        call    writeFile
        mov     ebx, dword[handle]
	call    closeFile



	push	ecx		;delay
	mov 	ecx,0
delay2:
	loop	delay2
	pop	ecx
	
	jmp	for

	
;;; we're done!
        ret
  • We create a delay using loops after turning LED on and after turning LED off, so that the blinking is slow enough to be visible. The number of loops for each delay is 2^32 = 4 294 967 296, as we set ecx to 0. The delay time being observed is about 4 seconds. The frequency of blinking is approximately 1 cycle/(2*4sec)=.125Hz.
  • The LED can be made blinking faster by decreasing the delay time. However, we do not implement a solution.