computertechniek hogeschool van utrecht / institute for computer, communication and media technology...
TRANSCRIPT
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
1Computertechniek
herhaling ARM assembler instructies geindexeerde adressering conditionele instructies en de flags subroutines, gebruik van de stack gebruik van het bordje: LEDs en LCD oefening
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
2Computertechniek
LDR R0, =value MOV R0, R1LDR R0, [ R1 ]STR R0, [ R1 ]ADD R0, R1, R2ADD R0, R1, #15B labelBL label
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
3Computertechniek
LDR R0, =value
R0
R1
R2
R3
R4
R5
R6
R7
R8
R9
R10
R11
R12
R13 = SP
R14 = LR
R15 = PC
registers
0000 0000
0000 0001
0000 0002
0000 0003
0000 0004
0000 0005
0000 0006
0000 0007
0000 0008
0000 0009
…….
FFFF FFFB
FFFF FFFC
FFFF FFFD
FFFF FFFE
FFFF FFFF
geheugen
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
4Computertechniek
MOV R0, R1
R0
R1
R2
R3
R4
R5
R6
R7
R8
R9
R10
R11
R12
R13 = SP
R14 = LR
R15 = PC
registers
0000 0000
0000 0001
0000 0002
0000 0003
0000 0004
0000 0005
0000 0006
0000 0007
0000 0008
0000 0009
…….
FFFF FFFB
FFFF FFFC
FFFF FFFD
FFFF FFFE
FFFF FFFF
geheugen
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
5Computertechniek
LDR R0, [ R1 ]
R0
R1 000 0004
R2
R3
R4
R5
R6
R7
R8
R9
R10
R11
R12
R13 = SP
R14 = LR
R15 = PC
registers
0000 0000
0000 0001
0000 0002
0000 0003
0000 0004
0000 0005
0000 0006
0000 0007
0000 0008
0000 0009
…….
FFFF FFFB
FFFF FFFC
FFFF FFFD
FFFF FFFE
FFFF FFFF
geheugen
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
6Computertechniek
STR R0, [ R1 ]
R0
R1 FFFF FFFB
R2
R3
R4
R5
R6
R7
R8
R9
R10
R11
R12
R13 = SP
R14 = LR
R15 = PC
registers
0000 0000
0000 0001
0000 0002
0000 0003
0000 0004
0000 0005
0000 0006
0000 0007
0000 0008
0000 0009
…….
FFFF FFFB
FFFF FFFC
FFFF FFFD
FFFF FFFE
FFFF FFFF
geheugen
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
7Computertechniek
ADD R3, R1, R2
R0
R1
R2
R3
R4
R5
R6
R7
R8
R9
R10
R11
R12
R13 = SP
R14 = LR
R15 = PC
registers
0000 0000
0000 0001
0000 0002
0000 0003
0000 0004
0000 0005
0000 0006
0000 0007
0000 0008
0000 0009
…….
FFFF FFFB
FFFF FFFC
FFFF FFFD
FFFF FFFE
FFFF FFFF
geheugen
+
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
8Computertechniek
B = branch
R0
R1
R2
R3
R4
R5
R6
R7
R8
R9
R10
R11
R12
R13 = SP
R14 = LR
R15 = PC
registers
0000 0000
0000 0001
0000 0002
0000 0003
0000 0004
0000 0005
0000 0006
0000 0007
0000 0008
0000 0009
…….
FFFF FFFB
FFFF FFFC
FFFF FFFD
FFFF FFFE
FFFF FFFF
geheugen
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
9Computertechniek
BL = branch and link
R0
R1
R2
R3
R4
R5
R6
R7
R8
R9
R10
R11
R12
R13 = SP
R14 = LR
R15 = PC
registers
0000 0000
0000 0001
0000 0002
0000 0003
0000 0004
0000 0005
0000 0006
0000 0007
0000 0008
0000 0009
…….
FFFF FFFB
FFFF FFFC
FFFF FFFD
FFFF FFFE
FFFF FFFF
geheugen
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
10Computertechniek
Variaties op LDR R0, [R1]:LDR R0, [ R1 ], #12LDR R0, [ R1, #12 ] LDR R0, [ R1, #12 ] !
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
11Computertechniek
LDR R0, [ R1 ]
R0
R1 000 0004
R2
R3
R4
R5
R6
R7
R8
R9
R10
R11
R12
R13 = SP
R14 = LR
R14 = PC
registers
0000 0000
0000 0001
0000 0002
0000 0003
0000 0004
0000 0005
0000 0006
0000 0007
0000 0008
0000 0009
…….
FFFF FFFB
FFFF FFFC
FFFF FFFD
FFFF FFFE
FFFF FFFF
geheugen
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
12Computertechniek
Addressing mode: Post-indexed
• Example: STR r0, [r1], #12
• To auto-’increment’ the base register to location 0x1f4 instead use:– STR r0, [r1], #-12
r1
0x200Original
BaseRegister
Memory
0x50x200
r0
0x5Source
Registerfor STR
Offset
12 0x20c
r1
0x20cUpdatedBaseRegister
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
13Computertechniek
LDR R0, [ R1 ], #4
R0
R1 000 0004
R2
R3
R4
R5
R6
R7
R8
R9
R10
R11
R12
R13 = SP
R14 = LR
R14 = PC
registers
0000 0000
0000 0001
0000 0002
0000 0003
0000 0004
0000 0005
0000 0006
0000 0007
0000 0008
0000 0009
…….
FFFF FFFB
FFFF FFFC
FFFF FFFD
FFFF FFFE
FFFF FFFF
geheugen
+0000 0008
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
14Computertechniek
Addressing mode: Pre-indexed
• Example: STR r0, [r1,#12]
• To store to location 0x1f4 instead use: STR r0, [r1,#-12]• To auto-increment base pointer to 0x20c use: STR r0, [r1, #12]!• If r2 contains 3, access 0x20c by multiplying this by 4:
– STR r0, [r1, r2, LSL #2]
r1
0x200Base
Register
Memory
0x5
0x200
r0
0x5Source
Registerfor STR
Offset
12 0x20c
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
15Computertechniek
LDR R0, [ R1, #4 ]
R0
R1 000 0004
R2
R3
R4
R5
R6
R7
R8
R9
R10
R11
R12
R13 = SP
R14 = LR
R14 = PC
registers
0000 0000
0000 0001
0000 0002
0000 0003
0000 0004
0000 0005
0000 0006
0000 0007
0000 0008
0000 0009
…….
FFFF FFFB
FFFF FFFC
FFFF FFFD
FFFF FFFE
FFFF FFFF
geheugen
+0000 0008
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
16Computertechniek
LDR R0, [ R1, #4 ] !
R0
R1 000 0004
R2
R3
R4
R5
R6
R7
R8
R9
R10
R11
R12
R13 = SP
R14 = LR
R14 = PC
registers
0000 0000
0000 0001
0000 0002
0000 0003
0000 0004
0000 0005
0000 0006
0000 0007
0000 0008
0000 0009
…….
FFFF FFFB
FFFF FFFC
FFFF FFFD
FFFF FFFE
FFFF FFFF
geheugen
+0000 0008
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
17Computertechniek
Alle instructies kunnen conditioneel zijn Load en store kunnen ook per half-word of
byteBij add / sub kan opt
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
18Computertechniek
LCD aansturen een scrollende text laten
zien
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
19Computertechniek
LCD
• file hello.zip• uitpakken naar lege directory (geen spaties in
de pathname…)• run ‘as is’ geeft “Hello world” op het display
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
20Computertechniek
main
LCD library
delay library
Chip startup code
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
21Computertechniek
LCD Library
Subroutines:
LCD_INIT
eenmalig aanroepen
LCD_CLEAR
maakt het display leeg, cursor naar eerste positie
LCD_PUTCHAR
print het char in R0, schuift nar volgende positie
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
22Computertechniek
Text vastleggen
hello: .asciz “Hello!”
.align
ldr r1, =hello
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
23Computertechniek
.global main
tekst:
.asciz "Hello world!"
.align
main:
@ save registers
stmfd sp!, { lr }
@ gebruik de LCD
bl LCD_INIT
bl LCD_CLEAR
ldr r1, =tekst
loop:
ldrb r0,[ r1 ]
add r1, r1, #1
cmp r0, #0
beq klaar
bl LCD_PUTCHAR
b loop
klaar:
@ return
ldmfd sp!, { pc }
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
24Computertechniek
bl LCD_INIT
bl LCD_CLEAR
ldr r1, =tekst
loop:
ldrb r0,[ r1 ]
add r1, r1, #1
cmp r0, #0
beq klaar
bl LCD_PUTCHAR
b loop
klaar:
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
25Computertechniek
Doen
• Test “Hello world”• Laat een andere text zien• Maak een subroutine die een asciz string
(R0 = pointer) laat zien op het LCD display (test deze subroutine)
• Laat een scrollende text zien op het LCD display
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
26Computertechniek
Scroll een text ‘over’ het display, bv:
Hello brave new
ello brave new w
llo brave new wo
lo brave new wor
o brave new worl
brave new world
brave new world.
En dan weer overnieuw.
Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology
27Computertechniek
Opdrachten:
1. Maak zelf het ‘loop’ optel programma af en test het op het bordje.
2. maak een programma dat 2 getallen vermenigvuldigt (door herhaald optellen). Het is wellicht handig eerst in C te schrijven hoe je dit zou doen.