CT-Lab_6_ALU_and_Branch_Ins.../bcd/app/main.s

159 lines
4.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
LDR R2, =ADDR_LED_15_0
STRH R0, [R2]
; Show R0 on 7-Segment
LDR R2, =ADDR_7_SEG_BIN_DS3_0
STRH R0, [R2]
; 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