CT-Lab_7_ControlStructures/code/app/main.s

169 lines
4.3 KiB
ArmAsm
Raw Normal View History

2022-11-03 13:33:48 +01:00
;* ------------------------------------------------------------------
;* -- _____ ______ _____ -
;* -- |_ _| | ____|/ ____| -
;* -- | | _ __ | |__ | (___ Institute of Embedded Systems -
;* -- | | | '_ \| __| \___ \ Zurich University of -
;* -- _| |_| | | | |____ ____) | Applied Sciences -
;* -- |_____|_| |_|______|_____/ 8401 Winterthur, Switzerland -
;* ------------------------------------------------------------------
;* --
;* -- Project : CT1 - Lab 7
;* -- Description : Control structures
;* --
;* -- $Id: main.s 3748 2016-10-31 13:26:44Z kesr $
;* ------------------------------------------------------------------
; -------------------------------------------------------------------
; -- Constants
; -------------------------------------------------------------------
AREA myCode, CODE, READONLY
THUMB
ADDR_LED_15_0 EQU 0x60000100
ADDR_LED_31_16 EQU 0x60000102
ADDR_7_SEG_BIN_DS1_0 EQU 0x60000114
ADDR_DIP_SWITCH_15_0 EQU 0x60000200
ADDR_HEX_SWITCH EQU 0x60000211
NR_CASES EQU 0xB
jump_table ; ordered table containing the labels of all cases
; STUDENTS: To be programmed
; END: To be programmed
; -------------------------------------------------------------------
; -- Main
; -------------------------------------------------------------------
main PROC
EXPORT main
read_dipsw ; Read operands into R0 and R1 and display on LEDs
; STUDENTS: To be programmed
2022-11-03 15:14:14 +01:00
LDR R0, =ADDR_DIP_SWITCH_15_0
LDRH R0, [R0] ; Load Values of DIP Switches 15-0 in R0
LDR R2, =ADDR_LED_15_0
STRH R0, [R2] ; Display R0 on LEDs 15-0
MOVS R1, R0 ; Coppy Bits to R1
LSRS R0, R0, #8 ; Shift Bits in R0 right to only have DIP SWITCH 15-8
LDR R2, =0xff ; Bitmask to get only lower Byte
ANDS R1, R1, R2 ; Only keep lower Byte in R1
LDR R2, =ADDR_LED_15_0
STRH R0, [R2]
2022-11-03 13:33:48 +01:00
; END: To be programmed
read_hexsw ; Read operation into R2 and display on 7seg.
; STUDENTS: To be programmed
2022-11-03 15:14:14 +01:00
LDR R2, =ADDR_HEX_SWITCH
LDRB R2, [R2]
LDR R3, =ADDR_7_SEG_BIN_DS1_0
STRB R2, [R3]
2022-11-03 13:33:48 +01:00
; END: To be programmed
case_switch ; Implement switch statement as shown on lecture slide
; STUDENTS: To be programmed
2022-11-03 15:14:14 +01:00
LDR R3, =0x0a
CMP R2, R3
BHI case_bright
LDR R3, =jump_table ; Get Address of Jumptable
LDRB R3, [R3, R2] ; Load Label Address from J
BX R3 ; GOTO Speified label
2022-11-03 13:33:48 +01:00
; END: To be programmed
; Add the code for the individual cases below
; - operand 1 in R0
; - operand 2 in R1
; - result in R0
case_dark
LDR R0, =0
B display_result
case_add
ADDS R0, R0, R1
B display_result
; STUDENTS: To be programmed
2022-11-03 15:14:14 +01:00
case_bright
LDR R0, =0xFFFF
B display_result
case_sub
SUBS R0, R0, R1
B display_result
case_mult
MULS R0, R1, R0
B display_result
case_and
ANDS R0, R0, R1
B display_result
case_or
ORRS R0, R0, R1
B display_result
case_xor
EORS R0, R0, R1
B display_result
case_not
MVNS R0, R0
B display_result
case_nand
ANDS R0, R0, R1
MVNS R0, R0
B display_result
case_nor
ORRS R0, R0, R1
MVNS R0, R0
B display_result
case_xnor
EORS R0, R0, R1
MVNS R0, R0
B display_result
2022-11-03 13:33:48 +01:00
; END: To be programmed
display_result ; Display result on LEDs
; STUDENTS: To be programmed
; END: To be programmed
B read_dipsw
ALIGN
ENDP
; -------------------------------------------------------------------
; -- End of file
; -------------------------------------------------------------------
END