J.P. Armstrong
/
IntToBinaryAssembly
Assembly procedure that represents binary using the LEDs on the mbed.
Revision 2:a81c9bc37084, committed 2011-01-28
- Comitter:
- jp
- Date:
- Fri Jan 28 02:40:35 2011 +0000
- Parent:
- 1:7490aeb7d770
- Commit message:
Changed in this revision
binasm.s | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/binasm.s Thu Jan 27 06:42:17 2011 +0000 +++ b/binasm.s Fri Jan 28 02:40:35 2011 +0000 @@ -1,50 +1,52 @@ + AREA |.data|, DATA, READWRITE + EXPORT leds + +;BIT MASKS FOR LED1...LED4 + +LED1 EQU 0x040000 +LED2 EQU 0x100000 +LED3 EQU 0x200000 +LED4 EQU 0x800000 +ALLLEDS EQU LED1 :OR: LED2 :OR: LED3 :OR: LED4 + +leds DCD LED1, LED2, LED3, LED4 + + ALIGN + AREA |.text|, CODE, READONLY EXPORT binasm +GPIO1BASE EQU 0x2009C020; GPIO port 1 base address +GPIOSETOFF EQU 0x18 +GPIOCLROFF EQU 0x1C + binasm PROC PUSH {R4, LR} - MOV R1, #0 - MOV R2, #0 - MOV R3, #0 - ; Load GPIO Port 1 base address in register R1 - LDR R1, =0x2009C020 ; 0x2009C020 = GPIO port 1 base address - LDR R4, =leds + LDR R1, =GPIO1BASE + LDR R4, =(leds+12) ; point to the last element of array ;CLEAR LEDS - MOV.W R2, #0xB40000 - STR R2, [R1,#0x1C] + MOV R2, #ALLLEDS + STR R2, [R1,#GPIOCLROFF] - ADD R3, R3, #12 ; COUNTER FOR LOOP + MOV R3, #4 ; COUNTER FOR LOOP ADD R0, R0, #1 ; INCREMENT PARAMETER BY 1 loop - ; CLEAR THE CARRY FLAG - ADC R0, R0, #0 - - LDR.W R2, [R4, R3] - LSRS R0, R0, #1 + LDR R2, [R4], #-4 ; load value from the address in R4 and decrement it by 4 + LSRS R0, R0, #1 ; shift R0 right and set carry to the shifted out bit - STRCC R2, [R1,#0x1C] ; if==0, clear LED bit - STRCS R2, [R1,#0x18] ; if==1, set LED bit + STRCC R2, [R1,#GPIOCLROFF] ; if==0, clear LED bit + STRCS R2, [R1,#GPIOSETOFF] ; if==1, set LED bit - CMP R3, #0 - SUB R3, R3, #4 + SUBS R3, R3, #1 BNE loop POP {R4, PC} ENDP - - AREA |.data|, DATA, READWRITE - EXPORT leds - -;BIT MASK FOR LED1...LED4 - -leds DCD 0x040000 - DCD 0x100000 - DCD 0x200000 - DCD 0x800000 ALIGN + END \ No newline at end of file
--- a/main.cpp Thu Jan 27 06:42:17 2011 +0000 +++ b/main.cpp Fri Jan 28 02:40:35 2011 +0000 @@ -1,6 +1,8 @@ // // INTEGER TO BINARY by J.P. Armstrong // http://www.armtronics.com/ +// +// Improved by Igor Skochinsky // // PART OF CODE FROM: // http://mbed.org/cookbook/Assembly-Language