151 lines
4.2 KiB
ArmAsm
151 lines
4.2 KiB
ArmAsm
; ------------------------------------------------------------------
|
||
; -- _____ ______ _____ -
|
||
; -- |_ _| | ____|/ ____| -
|
||
; -- | | _ __ | |__ | (___ Institute of Embedded Systems -
|
||
; -- | | | '_ \| __| \___ \ Zurich University of -
|
||
; -- _| |_| | | | |____ ____) | Applied Sciences -
|
||
; -- |_____|_| |_|______|_____/ 8401 Winterthur, Switzerland -
|
||
; ------------------------------------------------------------------
|
||
; --
|
||
; -- table.s
|
||
; --
|
||
; -- CT1 P04 Ein- und Ausgabe von Tabellenwerten
|
||
; --
|
||
; -- $Id: table.s 800 2014-10-06 13:19:25Z ruan $
|
||
; ------------------------------------------------------------------
|
||
;Directives
|
||
PRESERVE8
|
||
THUMB
|
||
; ------------------------------------------------------------------
|
||
; -- Symbolic Literals
|
||
; ------------------------------------------------------------------
|
||
ADDR_DIP_SWITCH_7_0 EQU 0x60000200
|
||
ADDR_DIP_SWITCH_15_8 EQU 0x60000201
|
||
ADDR_DIP_SWITCH_31_24 EQU 0x60000203
|
||
ADDR_LED_7_0 EQU 0x60000100
|
||
ADDR_LED_15_8 EQU 0x60000101
|
||
ADDR_LED_23_16 EQU 0x60000102
|
||
ADDR_LED_31_24 EQU 0x60000103
|
||
ADDR_BUTTONS EQU 0x60000210
|
||
ADDR_7_SEGMENT EQU 0x60000114
|
||
|
||
BITMASK_KEY_T0 EQU 0x01
|
||
BITMASK_LOWER_NIBBLE EQU 0x0F
|
||
SHIFT_BITS_MSB EQU 0x08
|
||
|
||
; ------------------------------------------------------------------
|
||
; -- Variables
|
||
; ------------------------------------------------------------------
|
||
AREA MyAsmVar, DATA, READWRITE
|
||
; STUDENTS: To be programmed
|
||
|
||
store_table SPACE 32 ; reserve 16 byte (4 words)
|
||
|
||
|
||
|
||
|
||
; END: To be programmed
|
||
ALIGN
|
||
|
||
; ------------------------------------------------------------------
|
||
; -- myCode
|
||
; ------------------------------------------------------------------
|
||
AREA myCode, CODE, READONLY
|
||
|
||
main PROC
|
||
EXPORT main
|
||
|
||
readInput
|
||
BL waitForKey ; wait for key to be pressed and released
|
||
; STUDENTS: To be programmed
|
||
; Read Valules from Dip Switches 7-0 to R0
|
||
LDR R0, =ADDR_DIP_SWITCH_7_0
|
||
LDRB R0, [R0]
|
||
|
||
; Write Values to LED 7-0 from R0
|
||
LDR R1, =ADDR_LED_7_0
|
||
STRB R0, [R1]
|
||
|
||
; Read Index from Dip Switches 15-8 to R1
|
||
LDR R1, =ADDR_DIP_SWITCH_15_8
|
||
LDRB R1, [R1]
|
||
LDR R2, =BITMASK_LOWER_NIBBLE
|
||
ANDS R1, R1, R2
|
||
|
||
|
||
; Write Index to LED 15-8 from R1
|
||
LDR R2, =ADDR_LED_15_8
|
||
STRB R1, [R2]
|
||
|
||
; Write Values to Store Table
|
||
MOVS R3, R1
|
||
LDR R2, =SHIFT_BITS_MSB
|
||
LSLS R3, R3, R2
|
||
ADDS R0, R0, R3 ; or w<>re besser
|
||
LDR R2, =store_table
|
||
ADDS R1, R1, R1
|
||
STRH R0, [R2, R1]
|
||
|
||
|
||
|
||
|
||
|
||
; Read Index from Dip Switches 15-8 to R1
|
||
; Todo: Maskierung
|
||
LDR R0, =ADDR_DIP_SWITCH_31_24
|
||
LDRB R0, [R0]
|
||
LDR R1, =BITMASK_LOWER_NIBBLE
|
||
ANDS R0, R0, R1
|
||
|
||
; Write Index to LED 15-8 from R1
|
||
LDR R1, =ADDR_LED_31_24
|
||
STRB R0, [R1]
|
||
|
||
; Read Values from Store Table
|
||
LDR R1, =store_table
|
||
ADDS R0, R0, R0
|
||
LDRH R0, [R1, R0]
|
||
|
||
; Write Values to LED 7-0 from R0
|
||
LDR R1, =ADDR_LED_23_16
|
||
STRB R0, [R1]
|
||
|
||
;Write Values to 7-Segment Display
|
||
LDR R1, =ADDR_7_SEGMENT
|
||
STRH R0, [R1]
|
||
|
||
|
||
; END: To be programmed
|
||
B readInput
|
||
ALIGN
|
||
|
||
; ------------------------------------------------------------------
|
||
; Subroutines
|
||
; ------------------------------------------------------------------
|
||
|
||
; wait for key to be pressed and released
|
||
waitForKey
|
||
PUSH {R0, R1, R2}
|
||
LDR R1, =ADDR_BUTTONS ; laod base address of keys
|
||
LDR R2, =BITMASK_KEY_T0 ; load key mask T0
|
||
|
||
waitForPress
|
||
LDRB R0, [R1] ; load key values
|
||
TST R0, R2 ; check, if key T0 is pressed
|
||
BEQ waitForPress
|
||
|
||
waitForRelease
|
||
LDRB R0, [R1] ; load key values
|
||
TST R0, R2 ; check, if key T0 is released
|
||
BNE waitForRelease
|
||
|
||
POP {R0, R1, R2}
|
||
BX LR
|
||
ALIGN
|
||
|
||
; ------------------------------------------------------------------
|
||
; End of code
|
||
; ------------------------------------------------------------------
|
||
ENDP
|
||
END
|