computertechniek hogeschool van utrecht / institute for computer, communication and media technology...

27
Hogeschool van Utrecht / Institute for Computer, Communicati on and Media Technology 1 Computertechniek herhaling: geindexeerd, CMP, stack operand2 geheugen indeling, pseudo-operaties oefeningen: LCD, hoofdletters

Upload: lesly-linsley

Post on 11-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

1Computertechniek

herhaling: geindexeerd, CMP, stack operand2 geheugen indeling, pseudo-operaties oefeningen: LCD, hoofdletters

Page 2: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

2Computertechniek

LDR R0, [ R1 ]:LDR R0, [ R1 ], #4LDR R0, [ R1, #4 ] LDR R0, [ R1, #4 ]

!

Page 3: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

3Computertechniek

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

Page 4: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

4Computertechniek

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

Page 5: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

5Computertechniek

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

Page 6: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

6Computertechniek

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

Page 7: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

7Computertechniek

CMP R1, R2CMP R1, #15CMN R1, R2CMN R1, #10

Page 8: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

8Computertechniek

CMP 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

-

flags

Page 9: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

9Computertechniek

CMN R1, #15

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

+

flags

Page 10: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

10Computertechniek

STMFD SP!, { R1-R9, R12 }

LDMFD SP!, { R1-R9, R12 }

Page 11: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

11Computertechniek

Stack

• A stack is an area of memory which grows as new data is “pushed”

onto the “top” of it, and shrinks as data is “popped” off the top.• stack pointer

• used to point the current “top” of the stack.

empty ascending / empty decending / full ascending / full decenuing

SP

PUSH {1,2,3}

1

2

3

POP

1

2Result of pop = 3SP

Page 12: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

12Computertechniek

Stack Operation• Traditionally, a stack grows down in memory, with the last “pushed”

value at the lowest address. The ARM also supports ascending stacks, where the stack structure grows up through memory.

• The value of the stack pointer can either:– Point to the last occupied address (Full stack)

• and so needs pre-decrementing (ie before the push)

– Point to the next occupied address (Empty stack)• and so needs post-decrementing (ie after the push)

• The stack type to be used is given by the postfix to the instruction:– STMFD / LDMFD : Full Descending stack

– STMFA / LDMFA : Full Ascending stack.

– STMED / LDMED : Empty Descending stack

– STMEA / LDMEA : Empty Ascending stack

• Note: ARM Compiler will always use a Full descending stack.

Page 13: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

13Computertechniek

Block Data Transfer instructie code

• The Load and Store Multiple instructions (LDM / STM) allow betweeen 1 and 16 registers to be transferred to or from memory.

• The transferred registers can be either:– Any subset of the current bank of registers (default).

– Any subset of the user mode bank of registers when in a priviledged mode (postfix instruction with a ‘^̂’).

Cond 1 0 0 P U S W L Rn Register list

Condition field Base register

Load/Store bit0 = Store to memory1 = Load from memory

Write- back bit0 = no write-back1 = write address into base

PSR and force user bit0 = don’t load PSR or force user mode1 = load PSR or force user mode

Up/Down bit0 = Down; subtract offset from base1 = Up ; add offset to base

Pre/Post indexing bit0 = Post; add offset after transfer,1 = Pre ; add offset before transfer

2831 22 16 023 21 1527 20 1924

Each bit corresponds to a particular register. For example:• Bit 0 set causes r0 to be transferred.• Bit 0 unset causes r0 not to be transferred.At least one register must be transferred as the list cannot be empty.

Page 14: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

14Computertechniek

Operand2:

MOV R0, R1ADD R0, R1, #2SUBC R0, R1, R2, LSL #5ADDS R1, R2, R3, ASR R4

Page 15: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

15Computertechniek

Page 16: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

16Computertechniek

Wat zit er in het geheugen van een programma:

• Code (text)• Globale data met initiele waarde (data)• Globale data zonder initiele waarde (bss)• Stack (evt lokale data)• Heap

Page 17: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

17Computertechniek

Page 18: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

18Computertechniek

Wat zit in een “image”

Code (text)Globale data met initiele waarde

(data)Globale data zonder initiele waarde (bss)StackHeap

Page 19: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

19Computertechniek

Wat kan/moet in ROM (read-only)

Code (text)Globale data met initiele waarde

(data)maar wel copieren naar RAM! Globale data zonder initiele waarde

(bss) Stack

Heap

Page 20: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

20Computertechniek

Code voor een ROMmable image

C zorgt zelf wel voor de juiste verdelingAssembler:

code moet in .textgeinitialiseerde schrijfbare data moet in .data

ongeinitialiseerde data hoort in .bss

Page 21: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

21Computertechniek

.global main

getal_1 : .word 11

getal_2 : .word 22

getal_3 : .word 33

som : .word 99999

main:

@ hier komt uw code:

done:

b done

Page 22: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

22Computertechniek

.global main.data

.align

getal_1 : .word 11

getal_2 : .word 22

getal_3 : .word 33

.bss

.align

som : .skip 4

.text

.align

main:

@ hier komt uw code:

done:

b done

Page 23: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

23Computertechniek

Text vastleggen (data segment)

.data

hello: .asciz ”Hello!”

.text

ldr r1, =hello

Page 24: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

24Computertechniek

Text vastleggen (text segment)

.text

hello: .asciz ”Hello!”

.align

ldr r1, =hello

Page 25: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

25Computertechniek

Schrijf een (nette!) subroutine LCD_PUTASCIZ die de 0-terminated string waar R0 naar wijst naar het LCD schrijft. Maak gebruik van een geindexeerde instructie (en natuurlijk van LCD_PUTCHAR).

Demonstreer dit, maak natuurlijk gebruik van .asciz.

Page 26: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

26Computertechniek

Schrijf een (nette!) subroutine UPCHAR die het ASCII character in R0, als dit een kleine letter is, omzet naar een hoofdletter.

Demonstreer deze subroutine door een variatie op LCD_PUTASCIZ te maken (bv LCD_PUTASCIZ_UPCHAR).

Page 27: Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  herhaling: geindexeerd, CMP, stack  operand2

Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology

27Computertechniek

Tips: ASCII lezen: byte-wise flags beinvloeden: S erachter vergelijken: CMP (geen S nodig) Wat is de ASCII waarde van kleine

letter a? Geen idee, ik gebruik gewoon ’a’…