De presentatie wordt gedownload. Even geduld aub

De presentatie wordt gedownload. Even geduld aub

2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 1  Herhaling ARM assembler instructies  branch instructie  conditionele instructies en de flags  oefening.

Verwante presentaties


Presentatie over: "2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 1  Herhaling ARM assembler instructies  branch instructie  conditionele instructies en de flags  oefening."— Transcript van de presentatie:

1 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 1  Herhaling ARM assembler instructies  branch instructie  conditionele instructies en de flags  oefening (simulator)  brach and link instructie  gebruik van de stack  oefening (bordje)

2 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 2 R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 = SP R14 = LR R15 = PC registers 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 geheugen ARM processor LPC2106 chip

3 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 3 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 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 geheugen

4 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 4 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 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 geheugen

5 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 5 LDR R0, [ R1 ] R0 R1000 0004 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 = SP R14 = LR R15 = PC registers 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 geheugen

6 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 6 STR R0, [ R1 ] R0 R1FFFF FFFC R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 = SP R14 = LR R15 = PC registers 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 geheugen

7 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 7 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 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 geheugen +

8 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 8 Branch instructions 2831240 Cond 1 0 1 L Offset Condition field Link bit 0 = Branch 1 = Branch with link 232527 Branch : B{ } label Branch with Link : BL{ } sub_routine_label

9 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 9 B label R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 = SP R14 = LR R15 = PC registers 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 geheugen

10 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 10 All instructions are conditionally executed! iedere instructie is conditioneel Bijna alle instructies kunnen de conditie flags zetten

11 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 11 Conditions

12 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 12 Zet de flags of laat ze ongewijzigd Gewoon een S achter de instructie –ANDr0, r1, r2 @ laat de flags ongewijzigd –ANDSr0, r1, r2 @ zet de flags

13 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 13 Drie getallen optellen – domme manier.global main getal_1 :.word 11 getal_2 :.word 22 getal_3 :.word 33 som :.word 99999 main: ldr r0, =0 ldr r1, =getal_1 ldr r2, [ r1 ] addr0, r0, r2 ldr r1, =getal_2 ldr r2, [ r1 ] addr0, r0, r2 ldr r1, =getal_3 ldr r2, [ r1 ] add r0, r0, r2 ldr r1, =som str r0, [ r1] done: b done

14 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 14 Drie getallen optellen – iets minder domme manier.global main getal_1 :.word 11 getal_2 :.word 22 getal_3 :.word 33 som :.word 99999 main: ldr r0, =0 ldr r1, =getal_1 ldr r2, [ r1 ] addr0, r0, r2 add r1, r1, #4 ldr r2, [ r1 ] addr0, r0, r2 add r1, r1, #4 ldr r2, [ r1 ] add r0, r0, r2 ldr r1, =som str r0, [ r1] done: b done

15 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 15 Voorbeeld loop LET OP CPSR.global main main: @ initialisatie ldr r2, =100 loop: @ loop body subs r2, r2, #1 bneloop@test op zero vlag!!! done: b done

16 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 16 Drie getallen optellen in een loop.global main getal_1 :.word 11 getal_2 :.word 22 getal_3 :.word 33 som :.word 99999 main: ldr r0, =0 @ initialisatie loop: @ loop body subs r2, r2, #1 bneloop ldr r1, =som str r0, [ r1] done: b done Zelf afmaken

17 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 17 Maak nu zelf het ‘loop’ optel programma af en test het in de simulator.

18 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 18 Branch instructions 2831240 Cond 1 0 1 L Offset Condition field Link bit 0 = Branch 1 = Branch with link 232527 Branch : B{ } label Branch with Link : BL{ } sub_routine_label

19 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 19 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 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 geheugen

20 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 20 Een subroutine gebruiken om op te tellen (1).global main getal_1 :.word 11 getal_2 :.word 22 getal_3 :.word 33 som :.word 99999 add: ldr r2, [ r1 ] addr0, r0, r2 movPC, LR main: ldr r0, =0 ldr r1, =getal_1 bladd ldr r1, =getal_2 bladd ldr r1, =getal_3 bladd ldr r1, =som str r0, [ r1] done: b done

21 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 21 Een subroutine gebruiken om op te tellen (2).global main getal_1 :.word 11 getal_2 :.word 22 getal_3 :.word 33 som :.word 99999 add: ldr r2, [ r1 ] add r1, r1, #4 addr0, r0, r2 movPC, LR main: ldr r0, =0 ldr r1, =getal_1 bladd ldr r1, =som str r0, [ r1] done: b done

22 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 22 Wat gaat hier mis?.global main getal_1 :.word 11 getal_2 :.word 22 getal_3 :.word 33 som :.word 99999 add_r0_r2: add r0, r0, r2 movPC, LR add1: ldr r2, [ r1 ] bladd_r0_r2 add r1, r1, #4 movpc, lr main: ldr r0, =0 ldr r1, =getal_1 bladd ldr r1, =som str r0, [ r1] …..

23 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 23 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 decending SP PUSH {1,2,3} 1 2 3 POP 1 2 Result of pop = 3 SP

24 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 24 Stack Operations 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.

25 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 25 assembler instructie formaat : multiple words van en naar geheugen (block transfer instructies) STMFD SP!, { R1-R9, R12 } LDMFD SP!, { R1-R9, R12 }

26 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 26 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 bit 0 = Store to memory 1 = Load from memory Write- back bit 0 = no write-back 1 = write address into base PSR and force user bit 0 = don’t load PSR or force user mode 1 = load PSR or force user mode Up/Down bit 0 = Down; subtract offset from base 1 = Up ; add offset to base Pre/Post indexing bit 0 = Post; add offset after transfer, 1 = Pre ; add offset before transfer 2831 22 160 2321 1527 201924 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.

27 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 27 Gebruik de stack.global main getal_1 :.word 11 getal_2 :.word 22 getal_3 :.word 33 som :.word 99999 add_r0_r2: stmfdsp!, { lr } add r0, r0, r2 ldmfdsp!, { pc } add1: stmfdsp!, { r2, lr } ldr r2, [ r1 ] bladd_r0_r2 add r1, r1, #4 ldmfdsp!, { r2, pc } main: ldr r0, =0 ldr r1, =getal_1 bladd ldr r1, =som str r0, [ r1] …..

28 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 28  sluit een bordje aan (parallel + USB)  installeer de files uit blink.zip  in een lege directory  let op: geen spaties in de pathname   dubbel-klik op de.ppr file  build  start debugger

29 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 29 zet onder file > target settings:  Target = Remote/TCP  Hostname = 127.0.0.1  Port = 8888 (als je netjes afsluit blijft zou dit moeten blijven staan)

30 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 30 Als je dit krijgt moet je onder control panel > system > hardware > device manager (select view > show hidden devices) > non plug-and- pray devices > MAC_MOT > driver instellen op status = started, type = automatic

31 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 31 Als je dit krijgt heb je debugger/loader niet afgesloten Als het echt niet werkt: de USB aansluiting er even uithalen om het bordje te resetten.

32 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 32 doen Het bestaande ‘blink’ programma uitproberen en begrijpen Laat de LEDs anders knipperen: iedere 2 seconden even (bv 200ms) aan Laat de LEDs ‘kitt’-style heen-en-weer aan gaan. Lezen pag 39 tot 42 “the IO system”

33 2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 33 Blink.global main main: @ configureer de hardware om de LEDs te gebruiken blLEDs_init loop: ldr r0, =0x0F blLEDs_write ldrr0, =( 500 * 1000 ) blWAIT_uS ldrr0, =0xF0 blLEDs_write ldrr0, =( 500 * 1000 ) blWAIT_uS b loop


Download ppt "2007-2008 PEMSY1http://www.voti.nl/hvu/PEMSY1 1  Herhaling ARM assembler instructies  branch instructie  conditionele instructies en de flags  oefening."

Verwante presentaties


Ads door Google