ECE251: Tuesday September 18

Size: px
Start display at page:

Download "ECE251: Tuesday September 18"

Transcription

1 ECE251: Tuesday September 18 Subroutine Parameter Passing (Important) Allocating Memory in Subroutines (Important) Recursive Subroutines (Good to know) Debugging Hints Programming Hints Preview of I/O (GPIO) as Time Allows Labs: #4 starts next week. Prework as always Homework: #3 due next Thursday, Sept. 27 Mid-Term Exam on October 4, week after next. Lab Practical #1 week of October 9 in lab. 1

2 But First, A Message From Lab #9! Another Interesting Project ST77735 SPI 128x160 TFT LCD Display Interfaced to TIVA Board in C Also Interfaced to Arduino Convert this to library callable by our Assembly Language Routines 1 or 2-person project. See me. 2

3 Stacks, PUSH, and POP PUSHes and POPs must be balanced and in opposite orders at subroutine level E.g. PUSH {Ra}, Allocate_30_words must be followed by Deallocate_30_words, POP {Rb} Otherwise higher level routines would not have the stack pointing to the right information after a subroutine exit (BX LR) One of the reasons these structures are called stacks, like stacking and unstacking plates. Unstacking occurs in exact opposite order of stacking. 3

4 Subroutines: Parameter Passing (8.4.1) Call by Value: Sends parameter VALUES (i.e. numbers) directly to/from subroutine These values can be in registers or the stack They have nothing to do with memory addresses Just give me the facts, ma am Don t need no stinkin addresses Call by Reference: Sends parameter value ADDRESSES to/from subroutine These addresses can be in registers or on the stack The content of these address is not passed directly 4

5 Call by Value: Swap Routine Label Op-Code Operand(s) Comment SWAP PUSH PUSH POP POP BX LR {R1} {R2} {R1} {R2} Is this a valid Subroutine? Why or why not? Where are the parameters when SWAP is called? Why are they Call by Value? 5

6 Call by Reference: Copy Array of Bytes Routine to copy array of bytes to a second area COPY Test CMP r0,#0 ; r0 is counter-test for 0 BXEQ LR ;Return if counter is 0 LDRB r3, [r1],#1 ;r3=[r1] r1=r1+1 (byte) STRB r3, [r2],#1 ;r3=[r2] r2=r2+1 (byte) SUB r0, #1 ;decrement counter B Test ;retry loop What are the subroutine s parameters? Which are call by reference? Why? How short can the copied array be? How long? How would we modify this to copy array of WORDS? What kind of loop is this (While,Until,For,...) 6

7 Subroutine Parameters and Memory Allocation Parameter passing: These are all valid methods - Use registers - Use the stack - Use global memory, i.e. any addresses with data you have defined Returning results: These are all valid methods - Use registers - Use the stack (We can create a location where the result will be placed) - Use global memory LOCAL VARIABLE ALLOCATION (ONLY by subroutine) - Allocated by the callee (called subroutine, not caller) - The following instruction efficiently allocates local variables: SUB SP, #40 ; allocate? words in the stack Local variable deallocation - Performed by the subroutine - Must always be done before subroutine exits. Why? - The following instruction efficiently deallocates local variables: ADD SP, #40 ; deallocate? words from the stack 7

8 Stack Frame - The region in the stack that holds subroutine parameters, the subroutine return address, local variables, and saved registers is referred to as the stack frame. - The stack frame is also called activation record, because it is a block of memory which is activated when a subroutine is called. SP after SUB SUB SP,#40 SP before SUB DECREASING Memory Local variables Saved registers Save return address Subroutine Incoming and Outgoing parameters Stack Stack Frame: Part created by called subroutine itself Part created by calling program 8

9 Stack Frame Look a little more at incoming and outgoing parameters That s where results go if they are in the stack (vs. registers or global memory Just like incoming parameters, outgoing parameters (return info to caller) must have space set aside by the calling program. Why? Local variables Saved registers Stack Frame: Part created by called subroutine itself What software creates the space for these outgoing parameters? Save return address Subroutine Incoming and Outgoing parameters Stack Part created by calling program 9

10 Accessing Parameters in the Stack Frame It s easy--just use normal indexing with SP. Offset will always be positive. Why? SP after SUB SR,#40 e.g. LDR r0,[sp,#20] Local variables Saved registers Created by Called Subroutine Save return address Incoming and outgoing parameters Stack 10

11 Accessing Local Variables in the Stack Frame It s not too hard--just use normal indexing with SP, like local variables. The challenge is computing the offset, which the programmer must do. You can equate the offset number to a label, making understanding of the program a little easier. E.g. STR ro, [SP,#Maxval] SP after SUB SR,#40 Local variables Saved registers Created by Called Subroutine e.g. LDR r0,[sp,#52] or STR r0,[sp,#52] Save return address Incoming and outgoing parameters Part created by calling program Stack 11

12 Recursive Functions A recursive function is one that solves its task by calling itself on smaller pieces of data. Recursive functions are good at showing how stack is used An effective tactic is to divide a problem into sub-problems of the same type as the original, solve those sub-problems, and combine the results 12

13 Defining Factorial(n) Product of the first n numbers n factorial(0) = 1 factorial(1) = 1 factorial(2) = 2 1 factorial(3) = factorial(4) = factorial(n) = n (n-1) 1 = 1 factorial(0) = 2 factorial(1) = 3 factorial(2) = 4 factorial(3) = n factorial(n-1) 13

14 Classic Recursion Example: Factorial Factorial is the classic educational example: 6! = 6 5! = 6 5 x 4! = 6 5 x 4 x 3! 6! = The factorial function can be written as a recursive function: ; Input: r0 is n ; Output: r0 is Fact(n) ; A bit hard to follow? Recursive functions often are! FACT CMP r0, #1 ;Is n <= 1? BLE ENDC ;If so, to ENDC PUSH {r0,lr} ;Save r0 (n) and lr on TOS SUB r0, r0, #1 ;n=n=1 BL FACT ;get FACT(n-1) in r0 POP {r1, lr} ;restore r1 (n), lr from TOS MUL r0, r1, r0 ;r0=n*fact(n-1) BX LR ;normal return ENDC MOV r0, #1 ;r0=fact(1)=1 BX LR ;end case return 14

15 Factorial Parameters Input to FACT is in r0, call by value Output is in r0, returns value Temporary n stored in stack as a value Try this by hand with input r0=3. I.e. compute 3! ; Input: r0 is n ; Output: r0 is Fact(n) ; A bit hard to follow? Recursive functions often are FACT CMP r0, #1 ;Is n <= 1? BLE ENDC ;If so, to ENDC PUSH {r0,lr} ;Save r0 (n) and lr on TOS SUB r0, r0, #1 ;n=n=1 BL FACT ;get FACT(n-1) in r0 POP {r1, lr] ;restore r1 (n), lr from TOS MUL r0, r1, r0 ;r0=n*fact(n-1) BX LR ;normal return ENDC MOV r0, #1 ;r0=fact(1)=1 BX LR ;end case return 15

16 Classic Example: Fibonacci Numbers f(n) = f(n-1) + f(n-2) f(0) = 0 f(1) = 1 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, How might we modify Factorial function to perform this function recursively? How would we write a program to compute Fibonacci series non-recursively? Would we need to store the entire series up to the number we re computing? 16

17 Analysis of fib(5) 5 fib(5) fib(4) 3 2 fib(3) fib(3) fib(2) fib(2) fib(1) fib(2) fib(1) fib(1) fib(0) fib(1) fib(0) 1 fib(1) 0 fib(0) 17

18 Recursion vs Iteration Any problem that can be solved recursively (calls itself) can also be solved iteratively (using loop). Recursive functions (vs. Iterative functions) Cons: Recursive functions are slow Recursive function take more memory Pros Recursive functions resembles the problem more naturally Recursive functions may be easier to program and debug IF the function is CAREFULLY created as recursive (see next slide) Try drawing a flow chart for an iterative function to compute a Fibonacci value to determine which is more natural 18

19 Recursive Functions PUSH LR (& working registers) onto stack before nested call POP LR (& working registers) off stack after nested return Just like any other nested subroutine calls 19

20 We are NOT going to go over the next 18 slides in detail! We will review them briefly to see how the stack is used in recursive subroutines. They are available to you to look at the details of subroutine calls, stack usage, and computation to compute a factorial. There are easier ways to do this! 20

21 Recursive Factorial in Assembly AREA main, CODE, READONLY EXPORT main ENTRY 0x x x x A 0x C 0x E 0x x x x C main PROC MOV r0, #0x03 stop B stop ENDP factorial PUSH {r4, lr} MOV r4, r0 CMP r4, #0x01 BNE NZ MOVS r0, #0x01 loop POP {r4, pc} NZ SUBS r0, r4, #1 MUL r0, r4, r0 B loop return 6 3 * factorial(2) return 2 2 * factorial(1) 1 Note implied BX LR instruction! END 21

22 Recursive Factorial in Assembly 0x x x x A 0x C 0x E 0x x x x C AREA main, CODE, READONLY EXPORT main ENTRY main MOV r0, #0x03 stop B stop factorial PUSH {r4, lr} MOV r4, r0 CMP r4, #0x01 BNE NZ MOVS r0, #0x01 loop POP {r4, pc} NZ SUBS r0, r4, #1 MUL r0, r4, r0 B loop END 0x xFFFFFFFF 0x pc lr sp r4 r0 Data Address 0x Memory 0xFFFFFFFF 0x x200005FC 0x200005F4 0x200005EC 0x200005E8 0x200005E4 0x200005E0 0x200005DC 0x200005D8 0x200005D4 0x

23 Recursive Factorial in Assembly 0x x x x A 0x C 0x E 0x x x x C AREA main, CODE, READONLY EXPORT main ENTRY main PROC MOV r0, #0x03 stop B stop ENDP factorial PUSH {r4, lr} MOV r4, r0 CMP r4, #0x01 BNE NZ MOVS r0, #0x01 loop POP {r4, pc} NZ SUBS r0, r4, #1 MUL r0, r4, r0 B loop END 0x x pc lr sp r4 r0 Data Address 0x Memory 0xFFFFFFFF 0x x200005FC 0x200005F4 0x200005EC 0x200005E8 0x200005E4 0x200005E0 0x200005DC 0x200005D8 0x200005D4 0x

24 Recursive Factorial in Assembly 0x x x x A 0x C 0x E 0x x x x C AREA main, CODE, READONLY EXPORT main ENTRY main PROC MOV r0, #0x03 stop B stop ENDP factorial PUSH {r4, lr} MOV r4, r0 CMP r4, #0x01 BNE NZ MOVS r0, #0x01 loop POP {r4, pc} NZ SUBS r0, r4, #1 MUL r0, r4, r0 B loop END 0x Order in which registers are specified is not important: the lowest register is always stored at the lowest address pc lr sp r4 r0 Data Address 0x Memory 0xFFFFFFFF 0x x200005FC 0x200005F4 0x200005EC 0x200005E8 0x200005E4 0x200005E0 0x200005DC 0x200005D8 0x200005D4 0x

25 Recursive Factorial in Assembly 0x x x x A 0x C 0x E 0x x x x C AREA main, CODE, READONLY EXPORT main ENTRY main PROC MOV r0, #0x03 stop B stop ENDP factorial PUSH {r4, lr} MOV r4, r0 CMP r4, #0x01 BNE NZ MOVS r0, #0x01 loop POP {r4, pc} NZ SUBS r0, r4, #1 MUL r0, r4, r0 B loop END 0x pc lr sp r4 r0 Data Address 0x Memory 0xFFFFFFFF 0x x200005FC 0x200005F4 0x200005EC 0x200005E8 0x200005E4 0x200005E0 0x200005DC 0x200005D8 0x200005D4 0x

26 Recursive Factorial in Assembly 0x x x x A 0x C 0x E 0x x x x C AREA main, CODE, READONLY EXPORT main ENTRY main PROC MOV r0, #0x03 stop B stop ENDP factorial PUSH {r4, lr} MOV r4, r0 CMP r4, #0x01 BNE NZ MOVS r0, #0x01 loop POP {r4, pc} NZ SUBS r0, r4, #1 MUL r0, r4, r0 B loop END 0x pc lr sp r4 r0 Data Address 0x Memory 0xFFFFFFFF 0x x200005FC 0x200005F4 0x200005EC 0x200005E8 0x200005E4 0x200005E0 0x200005DC 0x200005D8 0x200005D4 0x

27 Recursive Factorial in Assembly 0x x x x A 0x C 0x E 0x x x x C AREA main, CODE, READONLY EXPORT main ENTRY main PROC MOV r0, #0x03 stop B stop ENDP factorial PUSH {r4, lr} MOV r4, r0 CMP r4, #0x01 BNE NZ MOVS r0, #0x01 loop POP {r4, pc} NZ SUBS r0, r4, #1 MUL r0, r4, r0 B loop END 0x pc lr sp r4 r0 Data Address 0x Memory 0xFFFFFFFF 0x x200005FC 0x200005F4 0x200005EC 0x200005E8 0x200005E4 0x200005E0 0x200005DC 0x200005D8 0x200005D4 0x

28 Recursive Factorial in Assembly 0x x x x A 0x C 0x E 0x x x x C AREA main, CODE, READONLY EXPORT main ENTRY main PROC MOV r0, #0x03 stop B stop ENDP factorial PUSH {r4, lr} MOV r4, r0 CMP r4, #0x01 BNE NZ MOVS r0, #0x01 loop POP {r4, pc} NZ SUBS r0, r4, #1 MUL r0, r4, r0 B loop END 0x pc lr sp r4 r0 Data Address 0x Memory 0xFFFFFFFF 0x x200005FC 0x200005F4 0x200005EC 0x200005E8 0x200005E4 0x200005E0 0x200005DC 0x200005D8 0x200005D4 0x

29 Recursive Factorial in Assembly 0x x x x A 0x C 0x E 0x x x x C AREA main, CODE, READONLY EXPORT main ENTRY main PROC MOV r0, #0x03 stop B stop ENDP factorial PUSH {r4, lr} MOV r4, r0 CMP r4, #0x01 BNE NZ MOVS r0, #0x01 loop POP {r4, pc} NZ SUBS r0, r4, #1 MUL r0, r4, r0 B loop END 0x pc lr sp r4 r0 Data Address 0x Memory 0xFFFFFFFF 0x x200005FC 0x200005F4 0x200005EC 0x200005E8 0x200005E4 0x200005E0 0x200005DC 0x200005D8 0x200005D4 0x

30 Recursive Factorial in Assembly 0x x x x A 0x C 0x E 0x x x x C AREA main, CODE, READONLY EXPORT main ENTRY main PROC MOV r0, #0x03 stop B stop ENDP factorial PUSH {r4, lr} MOV r4, r0 CMP r4, #0x01 BNE NZ MOVS r0, #0x01 loop POP {r4, pc} NZ SUBS r0, r4, #1 MUL r0, r4, r0 B loop END 0x x200005E8 1 1 pc lr sp r4 r0 Data Address 0x Memory 0xFFFFFFFF 0x x200005FC 0x200005F4 0x200005EC 0x200005E8 0x200005E4 0x200005E0 0x200005DC 0x200005D8 0x200005D4 0x

31 Recursive Factorial in Assembly 0x x x x A 0x C 0x E 0x x x x C AREA main, CODE, READONLY EXPORT main ENTRY main PROC MOV r0, #0x03 stop B stop ENDP factorial PUSH {r4, lr} MOV r4, r0 CMP r4, #0x01 BNE NZ MOVS r0, #0x01 loop POP {r4, pc} NZ SUBS r0, r4, #1 MUL r0, r4, r0 B loop END 0x E 0x200005E8 1 1 pc lr sp r4 r0 Data Address 0x Memory 0xFFFFFFFF 0x x200005FC 0x200005F4 0x200005EC 0x200005E8 0x200005E4 0x200005E0 0x200005DC 0x200005D8 0x200005D4 0x

32 Recursive Factorial in Assembly 0x x x x A 0x C 0x E 0x x x x C AREA main, CODE, READONLY EXPORT main ENTRY main PROC MOV r0, #0x03 stop B stop ENDP factorial PUSH {r4, lr} MOV r4, r0 CMP r4, #0x01 BNE NZ MOVS r0, #0x01 loop POP {r4, pc} NZ SUBS r0, r4, #1 MUL r0, r4, r0 B loop END 2 1 pc lr sp r4 r0 Data Address 0x Memory 0xFFFFFFFF 0x x200005FC 0x200005F4 0x200005EC 0x200005E8 0x200005E4 0x200005E0 0x200005DC 0x200005D8 0x200005D4 0x

33 Recursive Factorial in Assembly 0x x x x A 0x C 0x E 0x x x x C AREA main, CODE, READONLY EXPORT main ENTRY main PROC MOV r0, #0x03 stop B stop ENDP factorial PUSH {r4, lr} MOV r4, r0 CMP r4, #0x01 BNE NZ MOVS r0, #0x01 loop POP {r4, pc} NZ SUBS r0, r4, #1 MUL r0, r4, r0 B loop END 2 2 pc lr sp r4 r0 Data Address 0x Memory 0xFFFFFFFF 0x x200005FC 0x200005F4 0x200005EC 0x200005E8 0x200005E4 0x200005E0 0x200005DC 0x200005D8 0x200005D4 0x

34 Recursive Factorial in Assembly 0x x x x A 0x C 0x E 0x x x x C AREA main, CODE, READONLY EXPORT main ENTRY main PROC MOV r0, #0x03 stop B stop ENDP factorial PUSH {r4, lr} MOV r4, r0 CMP r4, #0x01 BNE NZ MOVS r0, #0x01 loop POP {r4, pc} NZ SUBS r0, r4, #1 MUL r0, r4, r0 B loop END 0x Order in which registers are specified is not important. 2 2 pc lr sp r4 r0 Data Address 0x Memory 0xFFFFFFFF 0x x200005FC 0x200005F4 0x200005EC 0x200005E8 0x200005E4 0x200005E0 0x200005DC 0x200005D8 0x200005D4 0x

35 Recursive Factorial in Assembly 0x x x x A 0x C 0x E 0x x x x C AREA main, CODE, READONLY EXPORT main ENTRY main PROC MOV r0, #0x03 stop B stop ENDP factorial PUSH {r4, lr} MOV r4, r0 CMP r4, #0x01 BNE NZ MOVS r0, #0x01 loop POP {r4, pc} NZ SUBS r0, r4, #1 MUL r0, r4, r0 B loop END 3 2 pc lr sp r4 r0 Data Address 0x Memory 0xFFFFFFFF 0x x200005FC 0x200005F4 0x200005EC 0x200005E8 0x200005E4 0x200005E0 0x200005DC 0x200005D8 0x200005D4 0x

36 Recursive Factorial in Assembly 0x x x x A 0x C 0x E 0x x x x C AREA main, CODE, READONLY EXPORT main ENTRY main PROC MOV r0, #0x03 stop B stop ENDP factorial PUSH {r4, lr} MOV r4, r0 CMP r4, #0x01 BNE NZ MOVS r0, #0x01 loop POP {r4, pc} NZ SUBS r0, r4, #1 MUL r0, r4, r0 B loop END 3 6 pc lr sp r4 r0 Data Address 0x Memory 0xFFFFFFFF 0x x200005FC 0x200005F4 0x200005EC 0x200005E8 0x200005E4 0x200005E0 0x200005DC 0x200005D8 0x200005D4 0x

37 Recursive Factorial in Assembly 0x x x x A 0x C 0x E 0x x x x C AREA main, CODE, READONLY EXPORT main ENTRY main PROC MOV r0, #0x03 stop B stop ENDP factorial PUSH {r4, lr} MOV r4, r0 CMP r4, #0x01 BNE NZ MOVS r0, #0x01 loop POP {r4, pc} NZ SUBS r0, r4, #1 MUL r0, r4, r0 B loop END 3 6 pc lr sp r4 r0 Data Address 0x Memory 0xFFFFFFFF 0x x200005FC 0x200005F4 0x200005EC 0x200005E8 0x200005E4 0x200005E0 0x200005DC 0x200005D8 0x200005D4 0x

38 Recursive Factorial in Assembly 0x x x x A 0x C 0x E 0x x x x C AREA main, CODE, READONLY EXPORT main ENTRY main PROC MOV r0, #0x03 stop B stop ENDP factorial PUSH {r4, lr} MOV r4, r0 CMP r4, #0x01 BNE NZ MOVS r0, #0x01 loop POP {r4, pc} NZ SUBS r0, r4, #1 MUL r0, r4, r0 B loop END 0x pc lr sp r4 r0 Data Address 0x Memory 0xFFFFFFFF 0x x200005FC 0x200005F4 0x200005EC 0x200005E8 0x200005E4 0x200005E0 0x200005DC 0x200005D8 0x200005D4 0x

39 Recursive Factorial in Assembly 0x x x x A 0x C 0x E 0x x x x C AREA main, CODE, READONLY EXPORT main ENTRY main PROC MOV r0, #0x03 stop B stop ENDP factorial PUSH {r4, lr} MOV r4, r0 CMP r4, #0x01 BNE NZ MOVS r0, #0x01 loop POP {r4, pc} NZ SUBS r0, r4, #1 MUL r0, r4, r0 B loop END 0x pc lr sp r4 r0 Data Address 0x Memory 0xFFFFFFFF 0x x200005FC 0x200005F4 0x200005EC 0x200005E8 0x200005E4 0x200005E0 0x200005DC 0x200005D8 0x200005D4 0x

40 Finished Topic of Stack & Subroutines Any Questions? Basic topic of HW #3 Will certainly be on Mid-Term Exam! Next lecture is on new topic: General Purpose or Parallel I/O Read Chapter 14 in text 40

41 Debugging Hardware If your system isn t working: Replace the TM4C board with a known working board. If the system now works, you had a defective board. If not: Change out ONE thing from non-working system e.g. the USB cable. Reboot board, reload.o file, reset board, rerun program in an identical manner to previously. If system doesn t work, there s a problem with your USB cable. If it does work, your USB cable is OK. Do same process with another part. Result will tell you if it s working or not. Replace any offending parts. Problem should be fixed. If not, the non-working system is now working! 41

42 Debugging Software Begin with a known, hardware working system (see previous slide) Be sure your program ends with a deadloop, so it doesn t run off a cliff when done and change program and data area on your board. Don t expect that by just running the same program again, it will give same answer UNLESS all program and data storage has been restored and board is reset. If you re getting wrong or no answers, you need to single step your program from the start, observing all changes in register and memory data values. Also note whether program area has somehow been changed. This should be obvious if program does weird things when stepped. 42

43 Debugging Software-cont d During single stepping, if you see that the results are different from your expectations, figure out what s wrong with your expectations* about what should be happening. The problem is almost certainly there. This means you to need to change your program, reassemble, reset and reload board and rerun single step again to assure it s now doing the right thing at the point you had problems with earlier. Continue this process throughout the program until you get to the end with nothing different than you expected, i.e. your program executed correctly. * If you don t know what to expect after each instruction, then THAT is your primary problem. 43

44 Tips for Writing Programs - Review Data and Data Structures are Key Think about how data will be stored in memory Draw a picture or diagram Processing Algorithm is Key Think about how to process data Draw a FLOWCHART Break Problem into manageable chunks One page or less if several branches Two pages if mostly in-line code Use helpful names rather than numbers for values (EQU). 44

45 Next Lecture I/O: 2/3 of course(important) General Purpose I/O aka GPIO aka Parallel I/O Read Chapter 14 in text GPIO is Fair Game on Mid-Term Exam! It will/would be minor in point contribution It will/would be broad vs. detailed See sample exam online (coming soon) 45

46 Stack Usage Example ; Main Program Test Program to exercise subroutine Smart ; Assume SP Initialized to 0x AREA mydata, DATA Array SPACE 0x100 ; Starts at 0x ASSUME ALL BYTES=0xFF Var1 DCW 0x12AB ; Assume initialized AREA myprog, CODE EXPORT main main ; Start of program LDR R1, =Array ; Get parameter address LDR R0, =Var1 ; Get second parameter address LDRB R2, [R0] ; Put the call-by-value data in R2 PUSH {R1,R2} ; Push R2 and then R1 onto stack SUB SP, #4 ; Make ROOM for return data BL Smart ; Call subroutine Smart Callret NOP ; Smart returns to here ; Undo stack changes, restore registers in main program Deadl B Deadl ; Done ; Smart PUSH {R1} ; Save R1 on stack SUB SP, #8 ; Create local storage LDRB R1, [SP, #CBV] ; Fetch call-by-value data from stack ADD R1, R1, #1 ; Increment it STR R1, [SP, #ROOM] ; Put Data where ROOM was made above ; Undo all local storage created in subroutine Smart BX LR ; BX to LR address 46

47 Stack Usage Example a. What actual code would be used to replace the commented line: ; Undo stack changes, restore registers in main program b. On the next (opposing) page, fill in the registers and memory table with hex values where memory values are defined, and show (to left of table) where pointer SP points when the processor reaches the location commented with. If a value can t be determined, leave it blank. If it is the address of an instruction, use its label (Deadl, etc.). In addition, to the right side of the memory map show where (i.e. annotate) (1) incoming and return parameters, (2) saved registers, (from any subroutine calls) and (3) local storage (in any subroutines) are stored. c. What should the values of CBV and ROOM be, to make the instructions with operate properly? CBV EQU ROOM EQU 47

48 Show SP Memory Value Annotation area: below or Register (Word or Byte) R0 R1 R2 SP LR 0x SP initialized to this addr. 0x200005FF 0x200005FE 0x200005FD 0x200005FC 0x200005FB 0x200005FA 0x200005F9 0x200005F7 0x200005F6 0x200005F5 0x200005F4 0x200005F3 0x200005F2 0x200005F1 0x200005EF 0x200005EE 0x200005ED 0x200005EC 0x200005EB 0x200005EA 0x200005E9 0x200005E8 0x200005E7 48

ECE251: Intro to Microprocessors Name: Solutions Mid Term Exam October 4, 2018

ECE251: Intro to Microprocessors Name: Solutions Mid Term Exam October 4, 2018 ECE251: Intro to Microprocessors Name: Solutions Mid Term Exam October 4, 2018 (PRINT) Instructions: No calculators, books, or cell phones; do not communicate with any other student. One side of a single

More information

ECE251: Tuesday September 11

ECE251: Tuesday September 11 ECE251: Tuesday September 11 Finish Branch related instructions Stack Subroutines Note: Lab 3 is a 2 week lab, starting this week and covers the Stack and Subroutines. Labs: Lab #2 is due this week. Lab

More information

ECE251: Tuesday September 12

ECE251: Tuesday September 12 ECE251: Tuesday September 12 Finish Branch related instructions Stack Subroutines Note: Lab 3 is a 2 week lab, starting this week and covers the Stack and Subroutines. Labs: Lab #2 is due this week. Lab

More information

ECE251: Thursday September 27

ECE251: Thursday September 27 ECE251: Thursday September 27 Exceptions: Interrupts and Resets Chapter in text and Lab #6. READ ALL this material! This will NOT be on the mid-term exam. Lab Practical Exam #1 Homework # due today at

More information

ECE251: Thursday September 13

ECE251: Thursday September 13 ECE251: Thursday September 13 Lab 9: Some Details Stack and Subroutines, continued--chapter 8 Stack Example SUBROUTINES More Details Initializing the Stack/Pointer Passing Parameters to Subroutines via

More information

EE251: Thursday September 20

EE251: Thursday September 20 EE251: Thursday September 20 Parallel I/O aka General Purpose I/O aka GPIO Common Devices: Switches, LEDs, Keypads Read Lab 4 carefully, and Chapter 14 in text Think about what you would like to review

More information

Subroutines and the Stack

Subroutines and the Stack 3 31 Objectives: A subroutine is a reusable program module A main program can call or jump to the subroutine one or more times The stack is used in several ways when subroutines are called In this lab

More information

EE251: Tuesday September 5

EE251: Tuesday September 5 EE251: Tuesday September 5 Shift/Rotate Instructions Bitwise logic and Saturating Instructions A Few Math Programming Examples ARM Assembly Language and Assembler Assembly Process Assembly Structure Assembler

More information

NET3001. Advanced Assembly

NET3001. Advanced Assembly NET3001 Advanced Assembly Arrays and Indexing supposed we have an array of 16 bytes at 0x0800.0100 write a program that determines if the array contains the byte '0x12' set r0=1 if the byte is found plan:

More information

Exam 1. Date: February 23, 2016

Exam 1. Date: February 23, 2016 Exam 1 Date: February 23, 2016 UT EID: Printed Name: Last, First Your signature is your promise that you have not cheated and will not cheat on this exam, nor will you help others to cheat on this exam:

More information

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design Professor Sherief Reda http://scale.engin.brown.edu School of Engineering Brown University Spring 2016 1 ISA is the HW/SW

More information

Advanced Assembly, Branching, and Monitor Utilities

Advanced Assembly, Branching, and Monitor Utilities 2 Advanced Assembly, Branching, and Monitor Utilities 2.1 Objectives: There are several different ways for an instruction to form effective addresses to acquire data, called addressing modes. One of these

More information

ARM Cortex-M4 Architecture and Instruction Set 4: The Stack and subroutines

ARM Cortex-M4 Architecture and Instruction Set 4: The Stack and subroutines ARM Cortex-M4 Architecture and Instruction Set 4: The Stack and subroutines M J Brockway February 13, 2016 The Cortex-M4 Stack SP The subroutine stack is full, descending It grows downwards from higher

More information

ARM Cortex-M4 Architecture and Instruction Set 3: Branching; Data definition and memory access instructions

ARM Cortex-M4 Architecture and Instruction Set 3: Branching; Data definition and memory access instructions ARM Cortex-M4 Architecture and Instruction Set 3: Branching; Data definition and memory access instructions M J Brockway February 17, 2016 Branching To do anything other than run a fixed sequence of instructions,

More information

EE319K Fall 2013 Exam 1B Modified Page 1. Exam 1. Date: October 3, 2013

EE319K Fall 2013 Exam 1B Modified Page 1. Exam 1. Date: October 3, 2013 EE319K Fall 2013 Exam 1B Modified Page 1 Exam 1 Date: October 3, 2013 UT EID: Printed Name: Last, First Your signature is your promise that you have not cheated and will not cheat on this exam, nor will

More information

Computer Organization & Assembly Language Programming (CSE 2312)

Computer Organization & Assembly Language Programming (CSE 2312) Computer Organization & Assembly Language Programming (CSE 2312) Lecture 16: Processor Pipeline Introduction and Debugging with GDB Taylor Johnson Announcements and Outline Homework 5 due today Know how

More information

Computer Organization & Assembly Language Programming (CSE 2312)

Computer Organization & Assembly Language Programming (CSE 2312) Computer Organization & Assembly Language Programming (CSE 2312) Lecture 15: Running ARM Programs in QEMU and Debugging with gdb Taylor Johnson Announcements and Outline Homework 5 due Thursday Midterm

More information

Instruction Set Architectures (4)

Instruction Set Architectures (4) Computer Architecture Week 06 Instruction Set Architectures (4) College of Information Science and Engineering Ritsumeikan University subroutines functions, procedures remember the next instruction s address

More information

EE319K Spring 2015 Exam 1 Page 1. Exam 1. Date: Feb 26, 2015

EE319K Spring 2015 Exam 1 Page 1. Exam 1. Date: Feb 26, 2015 EE319K Spring 2015 Exam 1 Page 1 Exam 1 Date: Feb 26, 2015 UT EID: Printed Name: Last, First Your signature is your promise that you have not cheated and will not cheat on this exam, nor will you help

More information

Stack Frames. September 2, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 September 2, / 15

Stack Frames. September 2, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 September 2, / 15 Stack Frames Geoffrey Brown Bryce Himebaugh Indiana University September 2, 2016 Geoffrey Brown, Bryce Himebaugh 2015 September 2, 2016 1 / 15 Outline Preserving Registers Saving and Restoring Registers

More information

Programming the ARM. Computer Design 2002, Lecture 4. Robert Mullins

Programming the ARM. Computer Design 2002, Lecture 4. Robert Mullins Programming the ARM Computer Design 2002, Lecture 4 Robert Mullins 2 Quick Recap The Control Flow Model Ordered list of instructions, fetch/execute, PC Instruction Set Architectures Types of internal storage

More information

Systems Architecture The Stack and Subroutines

Systems Architecture The Stack and Subroutines Systems Architecture The Stack and Subroutines The Stack p. 1/9 The Subroutine Allow re-use of code Write (and debug) code once, use it many times A subroutine is called Subroutine will return on completion

More information

Bonus Lecture: Fibonacci

Bonus Lecture: Fibonacci Bonus Lecture: Fibonacci ECE 362 https://engineering.purdue.edu/ee362/ Rick Reading You could try looking up recurisve function in your textbook. Recursive Fibonacci if (x < 2) return fibonacci(x 1) +

More information

Course Administration

Course Administration Fall 2018 EE 3613: Computer Organization Chapter 2: Instruction Set Architecture Introduction 4/4 Avinash Karanth Department of Electrical Engineering & Computer Science Ohio University, Athens, Ohio 45701

More information

The Stack. Lecture 15: The Stack. The Stack. Adding Elements. What is it? What is it used for?

The Stack. Lecture 15: The Stack. The Stack. Adding Elements. What is it? What is it used for? Lecture 15: The Stack The Stack What is it? What is it used for? A special memory buffer (outside the CPU) used as a temporary holding area for addresses and data The stack is in the stack segment. The

More information

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution 1. (40 points) Write the following subroutine in x86 assembly: Recall that: int f(int v1, int v2, int v3) { int x = v1 + v2; urn (x + v3) * (x v3); Subroutine arguments are passed on the stack, and can

More information

ARM Assembler Workbook. CS160 Computer Organization Version 1.1 October 27 th, 2002 Revised Fall 2005

ARM Assembler Workbook. CS160 Computer Organization Version 1.1 October 27 th, 2002 Revised Fall 2005 ARM Assembler Workbook CS160 Computer Organization Version 1.1 October 27 th, 2002 Revised Fall 2005 ARM University Program Version 1.0 January 14th, 1997 Introduction Aim This workbook provides the student

More information

EE319K Exam 1 Summer 2014 Page 1. Exam 1. Date: July 9, Printed Name:

EE319K Exam 1 Summer 2014 Page 1. Exam 1. Date: July 9, Printed Name: EE319K Exam 1 Summer 2014 Page 1 Exam 1 Date: July 9, 2014 UT EID: Printed Name: Last, First Your signature is your promise that you have not cheated and will not cheat on this exam, nor will you help

More information

Chapters 5. Load & Store. Embedded Systems with ARM Cortex-M. Updated: Thursday, March 1, 2018

Chapters 5. Load & Store. Embedded Systems with ARM Cortex-M. Updated: Thursday, March 1, 2018 Chapters 5 Load & Store Embedded Systems with ARM Cortex-M Updated: Thursday, March 1, 2018 Overview: Part I Machine Codes Branches and Offsets Subroutine Time Delay 2 32-Bit ARM Vs. 16/32-Bit THUMB2 Assembly

More information

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design Professor Sherief Reda http://scale.engin.brown.edu School of Engineering Brown University Spring 2014 Sources: Computer

More information

Highlights. FP51 (FPGA based 1T 8051 core)

Highlights. FP51 (FPGA based 1T 8051 core) Copyright 2017 PulseRain Technology, LLC. FP51 (FPGA based 1T 8051 core) 10555 Scripps Trl, San Diego, CA 92131 858-877-3485 858-408-9550 http://www.pulserain.com Highlights 1T 8051 Core Intel MCS-51 Compatible

More information

Lab5 2-Nov-18, due 16-Nov-18 (2 weeks duration) Lab6 16-Nov-19, due 30-Nov-18 (2 weeks duration)

Lab5 2-Nov-18, due 16-Nov-18 (2 weeks duration) Lab6 16-Nov-19, due 30-Nov-18 (2 weeks duration) CS1021 AFTER READING WEEK Mid-Semester Test NOW Thurs 8th Nov @ 9am in Goldsmith Hall (ALL students to attend at 9am) Final 2 Labs Lab5 2-Nov-18, due 16-Nov-18 (2 weeks duration) Lab6 16-Nov-19, due 30-Nov-18

More information

CMPSCI 201 Fall 2006 Midterm #2 November 20, 2006 SOLUTION KEY

CMPSCI 201 Fall 2006 Midterm #2 November 20, 2006 SOLUTION KEY CMPSCI 201 Fall 2006 Midterm #2 November 20, 2006 SOLUTION KEY Professor William T. Verts 10 Points Trace the following circuit, called a demultiplexer, and show its outputs for all possible inputs.

More information

F28HS Hardware-Software Interface. Lecture 10: ARM Assembly Language 5

F28HS Hardware-Software Interface. Lecture 10: ARM Assembly Language 5 F28HS Hardware-Software Interface Lecture 10: ARM Assembly Language 5 Software interrupt SWI operand operand is interrupt number halts program saves PC branches to interrupt service code corresponding

More information

Exam 1 Fun Times. EE319K Fall 2012 Exam 1A Modified Page 1. Date: October 5, Printed Name:

Exam 1 Fun Times. EE319K Fall 2012 Exam 1A Modified Page 1. Date: October 5, Printed Name: EE319K Fall 2012 Exam 1A Modified Page 1 Exam 1 Fun Times Date: October 5, 2012 Printed Name: Last, First Your signature is your promise that you have not cheated and will not cheat on this exam, nor will

More information

EE445M/EE380L.6 Quiz 2 Spring 2017 Solution Page 1 of 5

EE445M/EE380L.6 Quiz 2 Spring 2017 Solution Page 1 of 5 EE445M/EE380L.6 Quiz 2 Spring 2017 Solution Page 1 of 5 First Name: Last Name: April 21, 2017, 10:00 to 10:50am Open book, open notes, calculator (no laptops, phones, devices with screens larger than a

More information

Systems I. Machine-Level Programming V: Procedures

Systems I. Machine-Level Programming V: Procedures Systems I Machine-Level Programming V: Procedures Topics abstraction and implementation IA32 stack discipline Procedural Memory Usage void swap(int *xp, int *yp) int t0 = *xp; int t1 = *yp; *xp = t1; *yp

More information

Control Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary

Control Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary Control Instructions Computer Organization Architectures for Embedded Computing Thursday, 26 September 2013 Many slides adapted from: Computer Organization and Design, Patterson & Hennessy 4th Edition,

More information

Control Instructions

Control Instructions Control Instructions Tuesday 22 September 15 Many slides adapted from: and Design, Patterson & Hennessy 5th Edition, 2014, MK and from Prof. Mary Jane Irwin, PSU Summary Previous Class Instruction Set

More information

16.317: Microprocessor Systems Design I Spring 2015

16.317: Microprocessor Systems Design I Spring 2015 16.317: Microprocessor Systems Design I Spring 2015 Exam 2 Solution 1. (16 points, 4 points per part) Multiple choice For each of the multiple choice questions below, clearly indicate your response by

More information

16.317: Microprocessor Systems Design I Fall 2015

16.317: Microprocessor Systems Design I Fall 2015 16.317: Microprocessor Systems Design I Fall 2015 Exam 2 Solution 1. (16 points, 4 points per part) Multiple choice For each of the multiple choice questions below, clearly indicate your response by circling

More information

Implementing Functions at the Machine Level

Implementing Functions at the Machine Level Subroutines/Functions Implementing Functions at the Machine Level A subroutine is a program fragment that... Resides in user space (i.e, not in OS) Performs a well-defined task Is invoked (called) by a

More information

CENG3420 Lecture 03 Review

CENG3420 Lecture 03 Review CENG3420 Lecture 03 Review Bei Yu byu@cse.cuhk.edu.hk 2017 Spring 1 / 38 CISC vs. RISC Complex Instruction Set Computer (CISC) Lots of instructions of variable size, very memory optimal, typically less

More information

Stacks and Subroutines

Stacks and Subroutines Chapters 8 Stacks and Subroutines Embedded Systems with ARM Cortext-M Updated: Tuesday, March 6, 2018 Basic Idea llarge programs are hard to handle lwe can break them to smaller programs lthey are called

More information

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture COMP 303 Computer Architecture Lecture 3 Comp 303 Computer Architecture 1 Supporting procedures in computer hardware The execution of a procedure Place parameters in a place where the procedure can access

More information

CSE Lecture In Class Example Handout

CSE Lecture In Class Example Handout CSE 30321 Lecture 07-09 In Class Example Handout Part A: A Simple, MIPS-based Procedure: Swap Procedure Example: Let s write the MIPS code for the following statement (and function call): if (A[i] > A

More information

CS153: Compilers Lecture 8: Compiling Calls

CS153: Compilers Lecture 8: Compiling Calls CS153: Compilers Lecture 8: Compiling Calls Stephen Chong https://www.seas.harvard.edu/courses/cs153 Announcements Project 2 out Due Thu Oct 4 (7 days) Project 3 out Due Tuesday Oct 9 (12 days) Reminder:

More information

Assembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Assembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Assembly III: Procedures Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu IA-32 (1) Characteristics Region of memory managed with stack discipline

More information

Research opportuni/es with me

Research opportuni/es with me Research opportuni/es with me Independent study for credit - Build PL tools (parsers, editors) e.g., JDial - Build educa/on tools (e.g., Automata Tutor) - Automata theory problems e.g., AutomatArk - Research

More information

Compiling Code, Procedures and Stacks

Compiling Code, Procedures and Stacks Compiling Code, Procedures and Stacks L03-1 RISC-V Recap Computational Instructions executed by ALU Register-Register: op dest, src1, src2 Register-Immediate: op dest, src1, const Control flow instructions

More information

MIPS Programming. A basic rule is: try to be mechanical (that is, don't be "tricky") when you translate high-level code into assembler code.

MIPS Programming. A basic rule is: try to be mechanical (that is, don't be tricky) when you translate high-level code into assembler code. MIPS Programming This is your crash course in assembler programming; you will teach yourself how to program in assembler for the MIPS processor. You will learn how to use the instruction set summary to

More information

Lecture V Toy Hardware and Operating System

Lecture V Toy Hardware and Operating System 2. THE Machine Lecture V Page 1 Lecture V Toy Hardware and Operating System 1. Introduction For use in our OS projects, we introduce THE Machine where THE is an acronym 1 for Toy HardwarE. We also introduce

More information

Exam 1. Date: February 23, 2018

Exam 1. Date: February 23, 2018 Exam 1 Date: February 23, 2018 UT EID: Printed Name: Last, First Your signature is your promise that you have not cheated and will not cheat on this exam, nor will you help others to cheat on this exam:

More information

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015 Branch Addressing Branch instructions specify Opcode, two registers, target address Most branch targets are near branch Forward or backward op rs rt constant or address 6 bits 5 bits 5 bits 16 bits PC-relative

More information

Exam 1. Date: Oct 4, 2018

Exam 1. Date: Oct 4, 2018 Exam 1 Date: Oct 4, 2018 UT EID: Professor: Valvano Printed Name: Last, First Your signature is your promise that you have not cheated and will not cheat on this exam, nor will you help others to cheat

More information

ASSEMBLY III: PROCEDURES. Jo, Heeseung

ASSEMBLY III: PROCEDURES. Jo, Heeseung ASSEMBLY III: PROCEDURES Jo, Heeseung IA-32 STACK (1) Characteristics Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address - address of top

More information

EE319K Spring 2016 Exam 1 Solution Page 1. Exam 1. Date: Feb 25, UT EID: Solution Professor (circle): Janapa Reddi, Tiwari, Valvano, Yerraballi

EE319K Spring 2016 Exam 1 Solution Page 1. Exam 1. Date: Feb 25, UT EID: Solution Professor (circle): Janapa Reddi, Tiwari, Valvano, Yerraballi EE319K Spring 2016 Exam 1 Solution Page 1 Exam 1 Date: Feb 25, 2016 UT EID: Solution Professor (circle): Janapa Reddi, Tiwari, Valvano, Yerraballi Printed Name: Last, First Your signature is your promise

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 4

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 4 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2018 Lecture 4 LAST TIME Enhanced our processor design in several ways Added branching support Allows programs where work is proportional to the input values

More information

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine Machine Language Instructions Introduction Instructions Words of a language understood by machine Instruction set Vocabulary of the machine Current goal: to relate a high level language to instruction

More information

Computer Organization & Assembly Language Programming (CSE 2312)

Computer Organization & Assembly Language Programming (CSE 2312) Computer Organization & Assembly Language Programming (CSE 2312) Lecture 17: More Processor Pipeline, Other Parallelism, and Debugging with GDB Taylor Johnson Announcements and Outline Programming assignment

More information

ARM PROGRAMMING. When use assembly

ARM PROGRAMMING. When use assembly ARM PROGRAMMING Bùi Quốc Bảo When use assembly Functions that cannot be implemented in C, such as special register accesses and exclusive accesses Timing-critical routines Tight memory requirements, causing

More information

Assembly III: Procedures. Jo, Heeseung

Assembly III: Procedures. Jo, Heeseung Assembly III: Procedures Jo, Heeseung IA-32 Stack (1) Characteristics Region of memory managed with stack discipline Grows toward lower addresses Register indicates lowest stack address - address of top

More information

(2) Part a) Registers (e.g., R0, R1, themselves). other Registers do not exists at any address in the memory map

(2) Part a) Registers (e.g., R0, R1, themselves). other Registers do not exists at any address in the memory map (14) Question 1. For each of the following components, decide where to place it within the memory map of the microcontroller. Multiple choice select: RAM, ROM, or other. Select other if the component is

More information

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 7. Procedures and the Stack

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 7. Procedures and the Stack Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB Lab # 7 Procedures and the Stack April, 2014 1 Assembly Language LAB Runtime Stack and Stack

More information

University of Texas at Austin Electrical and Computer Engineering Department. EE319K, Embedded Systems, Spring 2013 Final Exam

University of Texas at Austin Electrical and Computer Engineering Department. EE319K, Embedded Systems, Spring 2013 Final Exam University of Texas at Austin Electrical and Computer Engineering Department EE319K, Embedded Systems, Spring 2013 Final Exam Directions There are 6 problems worth a total of 100 points. The number of

More information

Grundlagen Microcontroller Processor Core. Günther Gridling Bettina Weiss

Grundlagen Microcontroller Processor Core. Günther Gridling Bettina Weiss Grundlagen Microcontroller Processor Core Günther Gridling Bettina Weiss 1 Processor Core Architecture Instruction Set Lecture Overview 2 Processor Core Architecture Computes things > ALU (Arithmetic Logic

More information

Lecture 4 (part 2): Data Transfer Instructions

Lecture 4 (part 2): Data Transfer Instructions Lecture 4 (part 2): Data Transfer Instructions CSE 30: Computer Organization and Systems Programming Diba Mirza Dept. of Computer Science and Engineering University of California, San Diego Assembly Operands:

More information

CS213. Machine-Level Programming III: Procedures

CS213. Machine-Level Programming III: Procedures CS213 Machine-Level Programming III: Procedures Topics IA32 stack discipline Register saving conventions Creating pointers to local variables IA32 Region of memory managed with stack discipline Grows toward

More information

EE251: Tuesday October 23

EE251: Tuesday October 23 EE251: Tuesday October 23 Higher Frequency Clock via Phase Locked Loop TIMER MODULE: SysTick-Basis of next week s lab Section 12.4 and 18 in text describes our SysTick Section 2.5 of Valvano s Real Time

More information

CMPSCI 201 Fall 2004 Midterm #2 Answers

CMPSCI 201 Fall 2004 Midterm #2 Answers CMPSCI 201 Fall 2004 Midterm #2 Answers Professor William T. Verts 15 Points You should be quite familiar by now with the single-precision floating point numeric format (one 32-bit word containing

More information

Signed/Unsigned Integer Arithmetic in C. Vineel Kovvuri

Signed/Unsigned Integer Arithmetic in C. Vineel Kovvuri Signed/Unsigned Integer Arithmetic in C Vineel Kovvuri http://vineelkovvuri.com Contents 1 Introduction 2 2 How signed-ness is represented in the hardware? 2 3 How signed-ness is interpreted in assembly?

More information

ARM ASSEMBLY PROGRAMMING

ARM ASSEMBLY PROGRAMMING ARM ASSEMBLY PROGRAMMING 1. part RAB Računalniška arhitektura 1 Intro lab : Addition in assembler Adding two variables : res := stev1 + stev2 Zbirni jezik Opis ukaza Strojni jezik ldr r1, stev1 R1 M[0x20]

More information

Architecture. Digital Computer Design

Architecture. Digital Computer Design Architecture Digital Computer Design Architecture The architecture is the programmer s view of a computer. It is defined by the instruction set (language) and operand locations (registers and memory).

More information

ECE 206, Fall 2001: Lab 3

ECE 206, Fall 2001: Lab 3 ECE 206, : Lab 3 Data Movement Instructions Learning Objectives This lab will give you practice with a number of LC-2 programming constructs. In particular you will cover the following topics: - Load/store

More information

Recitation: Attack Lab

Recitation: Attack Lab 15-213 Recitation: Attack Lab TA 11 Feb 2017 Agenda Reminders Stacks Attack Lab Activities Reminders Bomb lab is due tomorrow (14 Feb, 2017)! But if you wait until the last minute, it only takes a minute!

More information

Design and Implementation Interrupt Mechanism

Design and Implementation Interrupt Mechanism Design and Implementation Interrupt Mechanism 1 Module Overview Study processor interruption; Design and implement of an interrupt mechanism which responds to interrupts from timer and UART; Program interrupt

More information

C-Style Strings. CS2253 Owen Kaser, UNBSJ

C-Style Strings. CS2253 Owen Kaser, UNBSJ C-Style Strings CS2253 Owen Kaser, UNBSJ Strings In C and some other low-level languages, strings are just consecutive memory locations that contain characters. A special null character (ASCII code 0)

More information

Computer Architecture and System Software Lecture 07: Assembly Language Programming

Computer Architecture and System Software Lecture 07: Assembly Language Programming Computer Architecture and System Software Lecture 07: Assembly Language Programming Instructor: Rob Bergen Applied Computer Science University of Winnipeg Announcements New assembly examples uploaded to

More information

Timers and Pulse Accumulator

Timers and Pulse Accumulator 7 7.1 Objectives: Tiva is equipped with six General Purpose Timer Modules named TIMERn. Additionally, each TIMERn consists of two 16 bit timers (A and B). Most GPIO pins can be assigned a TIMERn as an

More information

Procedure-Calling Conventions October 30

Procedure-Calling Conventions October 30 Procedure-Calling Conventions October 30 CSC201 Section 002 Fall, 2000 Saving registers Registers are inevitably used by subroutines; changes their! Registers have global scope; calling procedures also

More information

CSE Lecture In Class Example Handout

CSE Lecture In Class Example Handout CSE 30321 Lecture 07-08 In Class Example Handout Part A: J-Type Example: If you look in your book at the syntax for j (an unconditional jump instruction), you see something like: e.g. j addr would seemingly

More information

Exam 1. EE319K Spring 2013 Exam 1 (Practice 1) Page 1. Date: February 21, 2013; 9:30-10:45am. Printed Name:

Exam 1. EE319K Spring 2013 Exam 1 (Practice 1) Page 1. Date: February 21, 2013; 9:30-10:45am. Printed Name: EE319K Spring 2013 Exam 1 (Practice 1) Page 1 Exam 1 Date: February 21, 2013; 9:30-10:45am Printed Name: Last, First Your signature is your promise that you have not cheated and will not cheat on this

More information

MIPS Instruction Set Architecture (2)

MIPS Instruction Set Architecture (2) MIPS Instruction Set Architecture (2) Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu

More information

Technical Information. Command overview of Vision Systems

Technical Information. Command overview of Vision Systems Technical Information Command overview of Vision Systems Image analysis command Grab image 0x01 X X X X Shutter speed 0x07 X X X X Synchronous flash 0x49 X X X X Video mode 0x00 X X Display 0x05 X X X

More information

Exam 1. Date: March 1, 2019

Exam 1. Date: March 1, 2019 Exam 1 Date: March 1, 2019 UT EID: Printed Name: Last, First Your signature is your promise that you have not cheated and will not cheat on this exam, nor will you help others to cheat on this exam: Signature:

More information

Scope: Global and Local. Concept of Scope of Variable

Scope: Global and Local. Concept of Scope of Variable Concept of Scope of Variable : Computer Architecture I Instructor: Prof. Bhagi Narahari Dept. of Computer Science Course URL: www.seas.gwu.edu/~bhagiweb/cs135/ In assembly, who has access to a memory location/variable?

More information

11/10/2016. Review the Problem to Be Solved. ECE 120: Introduction to Computing. What Shall We Keep in the Registers? Where Are the Pieces in Memory?

11/10/2016. Review the Problem to Be Solved. ECE 120: Introduction to Computing. What Shall We Keep in the Registers? Where Are the Pieces in Memory? University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering ECE 120: Introduction to Computing Letter Frequency Coding Review the Problem to Be Solved The task: given an ASCII

More information

ENCM 369 Winter 2016 Lab 11 for the Week of April 4

ENCM 369 Winter 2016 Lab 11 for the Week of April 4 page 1 of 13 ENCM 369 Winter 2016 Lab 11 for the Week of April 4 Steve Norman Department of Electrical & Computer Engineering University of Calgary April 2016 Lab instructions and other documents for ENCM

More information

Chapter 10 Memory Model for Program Execution. Problem

Chapter 10 Memory Model for Program Execution. Problem Chapter 10 Memory Model for Program Execution Original slides by Chris Wilcox, Colorado State University Problem How do we allocate memory during the execution of a program written in C?! Programs need

More information

ARM Assembly Programming II

ARM Assembly Programming II ARM Assembly Programming II Computer Organization and Assembly Languages Yung-Yu Chuang 2007/11/26 with slides by Peng-Sheng Chen GNU compiler and binutils HAM uses GNU compiler and binutils gcc: GNU C

More information

ARM Assembly Programming

ARM Assembly Programming Introduction ARM Assembly Programming The ARM processor is very easy to program at the assembly level. (It is a RISC) We will learn ARM assembly programming at the user level and run it on a GBA emulator.

More information

EE 332 Real Time Systems Midterm Examination Solution Friday February 13, :30 pm to 4:30 pm

EE 332 Real Time Systems Midterm Examination Solution Friday February 13, :30 pm to 4:30 pm EE 332 Real Time Systems Midterm Examination Solution Friday February 13, 2004 2:30 pm to 4:30 pm Student Name Student Number Question Mark #1 / 15 #2 / 20 #3 / 25 TOTAL / 60 General: Two hours (2:30 pm

More information

Practical 1 Review. ECE Rick

Practical 1 Review. ECE Rick Practical 1 Review ECE 362 https://engineering.purdue.edu/ee362/ Rick Lab TA Survey We do a midterm review of lab TAs. Survey link is at the bottom of the "Lab Experiments" page. Complements? Criticism?

More information

Code Generation. Lecture 12

Code Generation. Lecture 12 Code Generation Lecture 12 1 Lecture Outline Topic 1: Basic Code Generation The MIPS assembly language A simple source language Stack-machine implementation of the simple language Topic 2: Code Generation

More information

Problem Sheet 1: ANSWERS (NOT ) (NOT ) 3. 37, ,

Problem Sheet 1: ANSWERS (NOT ) (NOT ) 3. 37, , Problem Sheet 1 1. Convert 512 10 toa16-bittwo's complement binarynumber [P&H, Ex.4.1] 2. Convert 1; 023 10 to a 16-bit two's complement binary number [P&H, Ex.4.2] 3. What hexadecimal number does the

More information

ORG ; TWO. Assembly Language Programming

ORG ; TWO. Assembly Language Programming Dec 2 Hex 2 Bin 00000010 ORG ; TWO Assembly Language Programming OBJECTIVES this chapter enables the student to: Explain the difference between Assembly language instructions and pseudo-instructions. Identify

More information

MIPS Functions and Instruction Formats

MIPS Functions and Instruction Formats MIPS Functions and Instruction Formats 1 The Contract: The MIPS Calling Convention You write functions, your compiler writes functions, other compilers write functions And all your functions call other

More information

The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002

The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002 15-213 The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002 Topics IA32 stack discipline Register saving conventions Creating pointers to local variables class07.ppt

More information

sarm User Guide Note that a space must appear before the operation field because any word beginning in the first column is a label

sarm User Guide Note that a space must appear before the operation field because any word beginning in the first column is a label sarm User Guide The sarm is program that implements an experimental CPU simulator. It is called experimental because it is not yet complete, and it also incorporates facilities that are not conventionally

More information

CS 61C: Great Ideas in Computer Architecture More MIPS, MIPS Functions

CS 61C: Great Ideas in Computer Architecture More MIPS, MIPS Functions CS 61C: Great Ideas in Computer Architecture More MIPS, MIPS Functions Instructors: John Wawrzynek & Vladimir Stojanovic http://inst.eecs.berkeley.edu/~cs61c/fa15 1 Machine Interpretation Levels of Representation/Interpretation

More information