189 lines
5.0 KiB
ArmAsm
189 lines
5.0 KiB
ArmAsm
; ------------------------------------------------------------------
|
|
; -- _____ ______ _____ -
|
|
; -- |_ _| | ____|/ ____| -
|
|
; -- | | _ __ | |__ | (___ Institute of Embedded Systems -
|
|
; -- | | | '_ \| __| \___ \ Zurich University of -
|
|
; -- _| |_| | | | |____ ____) | Applied Sciences -
|
|
; -- |_____|_| |_|______|_____/ 8401 Winterthur, Switzerland -
|
|
; ------------------------------------------------------------------
|
|
; --
|
|
; -- main.s
|
|
; --
|
|
; -- CT1 P06 "ALU und Sprungbefehle" mit MUL
|
|
; --
|
|
; -- $Id: main.s 4857 2019-09-10 17:30:17Z akdi $
|
|
; ------------------------------------------------------------------
|
|
;Directives
|
|
PRESERVE8
|
|
THUMB
|
|
|
|
; ------------------------------------------------------------------
|
|
; -- Address Defines
|
|
; ------------------------------------------------------------------
|
|
|
|
ADDR_LED_15_0 EQU 0x60000100
|
|
ADDR_LED_31_16 EQU 0x60000102
|
|
ADDR_DIP_SWITCH_7_0 EQU 0x60000200
|
|
ADDR_DIP_SWITCH_15_8 EQU 0x60000201
|
|
ADDR_7_SEG_BIN_DS3_0 EQU 0x60000114
|
|
ADDR_BUTTONS EQU 0x60000210
|
|
|
|
ADDR_LCD_RED EQU 0x60000340
|
|
ADDR_LCD_GREEN EQU 0x60000342
|
|
ADDR_LCD_BLUE EQU 0x60000344
|
|
LCD_BACKLIGHT_FULL EQU 0xffff
|
|
LCD_BACKLIGHT_OFF EQU 0x0000
|
|
|
|
MASK_LOW_NIBBLE EQU 0xf
|
|
FACTOR_10 EQU 0xa
|
|
BITMASK_KEY_T0 EQU 0x01
|
|
|
|
; ------------------------------------------------------------------
|
|
; -- myCode
|
|
; ------------------------------------------------------------------
|
|
AREA myCode, CODE, READONLY
|
|
|
|
ENTRY
|
|
|
|
main PROC
|
|
export main
|
|
|
|
; STUDENTS: To be programmed
|
|
|
|
LDR R2, =MASK_LOW_NIBBLE
|
|
|
|
; Load BCD Tens in R0
|
|
LDR R0, =ADDR_DIP_SWITCH_15_8
|
|
LDRB R0, [R0]
|
|
ANDS R0, R0, R2
|
|
|
|
; Load BCD Ones in R1
|
|
LDR R1, =ADDR_DIP_SWITCH_7_0
|
|
LDRB R1, [R1]
|
|
ANDS R1, R1, R2
|
|
|
|
; Check if T0 is pressed. If pressed goto CalcByMult
|
|
LDR R3, =ADDR_BUTTONS ; load base address of keys
|
|
LDR R4, =BITMASK_KEY_T0 ; load key mask T0
|
|
LDRB R2, [R3] ; load key values
|
|
TST R2, R4 ; check, if key T0 is pressed
|
|
BEQ CalcByMult ; goto CalcByMult
|
|
|
|
|
|
CalcByBitShift
|
|
; set the LCD background to red
|
|
LDR R2, =ADDR_LCD_RED
|
|
LDR R3, =0xffff
|
|
STRH R3, [R2]
|
|
LDR R2, =ADDR_LCD_BLUE
|
|
LDR R3, =0x0
|
|
STRH R3, [R2]
|
|
|
|
; Calculate Bin Value to R2 by Bit Shifting
|
|
; R2 = R0 * 10
|
|
LSLS R2, R0, #3
|
|
LSLS R3, R0, #1
|
|
ADDS R2, R2, R3
|
|
ADDS R2, R2, R1
|
|
|
|
EndCalcByBitShift
|
|
|
|
; goto EndCalcByMult
|
|
B EndCalcByMult
|
|
|
|
CalcByMult
|
|
|
|
; set the LCD background to blue
|
|
LDR R2, =ADDR_LCD_RED
|
|
LDR R3, =0x0
|
|
STRH R3, [R2]
|
|
LDR R2, =ADDR_LCD_BLUE
|
|
LDR R3, =0xffff
|
|
STRH R3, [R2]
|
|
|
|
; Calculate Bin Value to R2 by Multiplication
|
|
; R2 = R0 * 10
|
|
LDR R2, =FACTOR_10
|
|
MULS R2, R0, R2
|
|
ADDS R2, R2, R1
|
|
|
|
EndCalcByMult
|
|
|
|
; Shift BCD Tens in high Nibble in R0
|
|
; Add BCD Ones in low Nibble in R0
|
|
LSLS R0, R0, #4
|
|
ORRS R0, R0, R1
|
|
|
|
; Add Bin Value in higher Byte in R0
|
|
LSLS R2, R2, #8
|
|
ORRS R0, R0, R2
|
|
|
|
; Show R0 on LEDs 15-0
|
|
LDR R3, =ADDR_LED_15_0
|
|
STRH R0, [R3]
|
|
|
|
; Show R0 on 7-Segment
|
|
LDR R3, =ADDR_7_SEG_BIN_DS3_0
|
|
STRH R0, [R3]
|
|
|
|
; Count positive Bits in Higher Byte of R2 to R1
|
|
LDR R1, =0 ; initialize R1 with 0
|
|
LDR R3, =0x1 ; mask to set first bit and to substract counter
|
|
LDR R4, =9 ; counter for loop
|
|
LSLS R2, R2, #16
|
|
CheckBitLoop
|
|
SUBS R4, R4, R3
|
|
BEQ EndCheckBitLoop ; goto EndCheckBitLoop if R4 (counter) = 0
|
|
LSLS R2, R2, #1 ; Shift Bits in R2
|
|
BCC CheckBitLoop ; goto CheckBitLoop if carry = 0
|
|
ORRS R1, R3 ; Add Carry to R1
|
|
LSLS R1, R1, #1 ; Shift Bits in R1
|
|
B CheckBitLoop ; goto checkBitLoop
|
|
EndCheckBitLoop
|
|
LSRS R1, R1, #1 ; Shift Bits in R1
|
|
|
|
; Rotate LEDs 31-16
|
|
LDR R2, =ADDR_LED_31_16
|
|
LDR R4, =17 ; Counter for LedRotationLoop
|
|
LedRotationLoop
|
|
SUBS R4, R4, R3
|
|
BEQ EndLedRotationLoop ; goto EndCheckBitLoop if R4 (counter) = 0
|
|
BL pause
|
|
STRH R1, [R2] ; Show R1 on LEDs 31-16
|
|
MOV R5, R1 ; Coppy R1 to R5
|
|
LSLS R5, R5, #16 ; Shift Bits in R5
|
|
ORRS R1, R1, R5 ; Coppy lower bytes of R1 in upper bytes in R1
|
|
RORS R1, R1, R3
|
|
B LedRotationLoop
|
|
EndLedRotationLoop
|
|
|
|
; END: To be programmed
|
|
|
|
B main
|
|
ENDP
|
|
|
|
;----------------------------------------------------
|
|
; Subroutines
|
|
;----------------------------------------------------
|
|
|
|
;----------------------------------------------------
|
|
; pause for disco_lights
|
|
pause PROC
|
|
PUSH {R0, R1}
|
|
LDR R1, =1
|
|
LDR R0, =0x000FFFFF
|
|
|
|
loop
|
|
SUBS R0, R0, R1
|
|
BCS loop
|
|
|
|
POP {R0, R1}
|
|
BX LR
|
|
ALIGN
|
|
ENDP
|
|
|
|
; ------------------------------------------------------------------
|
|
; End of code
|
|
; ------------------------------------------------------------------
|
|
END
|