Assembly ARM. Execution flow MIPS. Calcolatori Elettronici e Sistemi Operativi. Examples MAX2 MAX3. return maximum between 2 integers

Size: px
Start display at page:

Download "Assembly ARM. Execution flow MIPS. Calcolatori Elettronici e Sistemi Operativi. Examples MAX2 MAX3. return maximum between 2 integers"

Transcription

1 Calcolatori Elettronici e Sistemi Operativi ARM Registers rules (ARM Procedure Call Standard [APCS]): name register use Assembly R0 <--> R0 function result (on function return) and first argument (on function entry) R1 <--> R1 second function argument (caller saved) R2 <--> R2 third function argument function argument (caller saved) R3 <--> R3 forth function argument function argument (caller saved) R4 <--> R4 local variable (callee saved) R8 <--> R9 local variable (callee saved) R9 <--> R9 local variable (callee saved) (or platform ecific data as base [static]) R10 <--> R10 local variable (callee saved) (or platform ecific data as limit [static]) <--> R11 pointer ip <--> R12 intra-procedure call scratch (can be used for local vars) <--> R13 pointer lr <--> R14 return address (HW) pc <--> R15 program counter (HW) Arguments above 4th: on MIPS Execution flow Registers rules (MIPS call convention): nome registro uso tipico zero <--> R0 0 (HW constant) at <--> R1 v0 <--> R2 function result (lowest 32 bits) v1 <--> R3 function result (highestest 32 bits, if needed) a0 <--> R4 first function argument a1 <--> R5 second function argument a2 <--> R6 third function argument a3 <--> R7 forth function argument t0 <--> R8 temporary (not saved) t7 <--> R15 temporary (not saved) s0 <--> R16 temporary (saved) s7 <--> R23 temporary (saved) t8 <--> R24 temporary (not saved) t9 <--> R25 temporary (not saved) k0 <--> R26 reserved for kernel k1 <--> R27 reserved for kernel Arguments above 4th: on gp <--> R28 global data pointer <--> R29 pointer <--> R30 pointer ra <--> R31 return address (HW) Examples MAX2 return maximum between 2 integers MAX3 return maximum among 3 integers

2 MAX2: ARM - (1) MAX2: ARM - (2) int max2(int a, int b) if (a>b) return a; else return b; max2:.global max2.type max2, %function // not mandatory cmp r0, r1 // if a>b ble ELSE int max2(int a, int b) if (a>b) return a; else return b; max2:.global max2.type max2, %function // not mandatory cmp r0, r1 // if a>b bgt ENDF // return a not needed THEN: // unused label mov r0, r0 // return a mov pc, lr ENDF: mov r0, r1 // else return b mov pc, lr return to caller ELSE: mov r0, r1 // return b mov pc, lr MAX2: ARM - (3) ARM condition suffixes int max2(int a, int b) if (a>b) return a; else return b; max2: conditional execution.global max2.type max2, %function // not mandatory cmp r0, r1 // if! a>b movle r0, r1 // return b mov pc, lr Main mnemonics EQ: equal NE: not equal LT: less than (for signed values) LE: less or equal (for signed values) GT: greater than (for signed values) GE: greater or equal (for signed values) HI: greater than (for unsigned values) LS: less or equal (for unsigned values)

3 MAX2: MIPS - (1) MAX2: MIPS - (2) int max2(int a, int b) if (a>b) return a; else return b; max2:.set noreorder.globl max2 slt $t0, $a1, $a0 // t0 <- (a>b) beq $t0, $zero, ELSE int max2(int a, int b) if (a>b) return a; else return b; max2:.set noreorder.globl max2 slt $t0, $a1, $a0 // t0 <- (a>b) beq $t0, $zero, ELSE THEN: // unused label move $v0, $a0 // return a ($v0<-$a0) // ELSE: move $v0, $a1 // return b ($v0<-$a1) // use delay slot THEN: // unused label // move $v0, $a0 // return a ($v0<-$a0) ELSE: // move $v0, $a1 // return b ($v0<-$a1) zero <--> R0 0 (costant) at <--> R1 v0 <--> R2 retval (LO) v1 <--> R3 retval (HI) a0 <--> R4 arg 1 a1 <--> R5 arg 2 zero <--> R0 0 (costant) at <--> R1 v0 <--> R2 retval (LO) v1 <--> R3 retval (HI) a0 <--> R4 arg 1 a1 <--> R5 arg 2 MAX2: MIPS - (3) MAX2: MIPS - (3) int max2(int a, int b) if (a>b) return a; else return b; max2:.set noreorder.globl max2 slt $t0, $a1, $a0 // t0 <- (a>b) bne $t0, $zero, ENDF move $v0, $a0 // return a ($v0<-$a0) int max2(int a, int b) if (a>b) return a; else return b; max2:.set noreorder.globl max2 slt $8, $5, $4 // t0 <- (a>b) bne $8, $0, ENDF move $2, $4 // return a ($v0<-$a0) use delay slot ENDF: move $v0, $a1 // return b ($v0<-$a1) // use delay slot ENDF: move $2, $5 // return b ($v0<-$a1) j $31 // zero <--> R0 0 (costant) at <--> R1 v0 <--> R2 retval (LO) v1 <--> R3 retval (HI) a0 <--> R4 arg 1 a1 <--> R5 arg 2 zero <--> R0 0 (costant) at <--> R1 v0 <--> R2 retval (LO) v1 <--> R3 retval (HI) a0 <--> R4 arg 1 a1 <--> R5 arg 2 Explicit register names

4 MAX3 - (1) MAX3 - (2) int max3a(int a, int b, int c) if (a>b) if (a>c) return a; else return c; else if (b>c) return b; else return c;.global max3 ARM max3: cmp r0, r1 // if a>b ble ELSE THEN: // unused label cmp r0, r2 movlt r0, r2 // if! a>c r0 <- c mov pc, lr // return (res. in r0) ELSE: cmp r1, r2 movge r0, r1 // if b >= c r0 <- b movlt r0, r2 // if b < c r0 <- c mov pc, lr // return (res. in r0).set noreorder.globl max3 MIPS max3: slt $t0, $a1, $a0 //t0 <- (a>b) (1) beq $t0, $zero, ELSE1 THEN1 // unused label slt $t0, $a2, $a0 //t0 <- (a>c) (2) beq $t0, $zero, ELSE2 THEN2: // unused label move $v0, $a0 //return a ELSE2: move $v0, $a2 //return c ELSE1: slt $t0, $a2, $a1 //t0 <- (b>c) (3) beq $t0, $zero, ELSE3 THEN3: // unused label move $v0, $a1 //return b ELSE3: move $v0, $a2 //return c int max3a(int a, int b, int c) /* m = MAX(a,b) */ /* return MAX(m,c) */ int m; if (a>b) m=a; else m=b; if (m>c) return m; else return c;.global max3 max3: cmp r0, r1 movlt r0, r1 // r0 <- max(a,b) cmp r0, r2 movlt r0, r2 // r0 <- max(r0,c) mov pc, lr // return ARM.set noreorder.globl max3 MIPS max3: slt $t0, $a1, $a0 // t0 <- (a>b) beq $t0, $zero, M1 move $v0, $a1 move $v0, $a0 // $v0 <- max(a,b) M1: slt $t0, $a2, $v0 // t0 <- (v0>c) bne $t0, $zero, ENDF // move $v0, $v0 move $v0, $a2 // $v0 <- max(v0,c) ENDF: Arrays and ARM Addressing Modes Examples strcpy uses strings factorial function (recursive) call Mul function call mcd function call LDMDA (Decrement After) <==> LDMFA (Full Ascending) LDMIA (Increment After) <==> LDMFD (Full Descending) LDMDB (Decrement Before) <==> LDMEA (Empty Ascending) es. ldmdb,, <==> ldmea,, LDMIB (Increment Before) <==> LDMED (Empty Descending) STMDA (Decrement After) <==> STMED (Empty Descending) STMIA (Increment After) <==> STMEA (Empty Ascending) STMDB (Decrement Before) <==> STMFD (Full Descending) es. stmdb!,, <==> stmfd!,, STMIB (Increment Before) <==> STMFA (Full Ascending)

5 Stack ARM Addressing Modes r15 (pc) r15 (pc) r15 (pc) Full Descending Empy Descending Empty Ascending ST: decrement before LD: increment after STMFD LDMFD STMDB LDMIA ST: decrement after LD: increment before STMED LDMED STMDA LDMIB ST: increment after LD: decrement before STMEA LDMEA STMIA LDMDB r15 (pc) Full Ascending ST: increment before LD: decrement after STMFA LDMFA STMIB LDMDA stmfd!,,,, ip, lr stmfd: store multiple full-descending (decrement before) start address = (5 registers to store)! update index register = save from here saving order is fixed (registers are saved in increasing order) and cannot be varied e.g.: stmfd!,, is not valid ARM Addressing Modes ARM Addressing Modes stmfd!,,,, ip, lr full-descending (decrement before) start address = (5 registers to store) restore from here stmfd!,,,, ip, lr full-descending (decrement before) start address = (5 registers to store) restore from here ldmfd!,,,, ip, lr full-descending (increment after) start address = = ldmea,,,, ip, lr empty-ascending (decrement before) start address = (5 registers to restore) fixed ( can change during the execution)

6 ARM ARM: function prologue/epilogue No allocation: local vars in r0-r3 - no other functions called increasing addresses local variables saved changed registers local-1 local-2 local-3 -r10 (if changed) (old) lr caller (after allocation) (on entry) Registers lr must be saved if another function is called. For -r14, only actually modified registers are saved. Registers r1-r3 must not be saved. Register r0 is the return value. Function arguments above fourth are in the caller. mov pc, lr return to caller Stack allocation (to save local registers): local vars in r0-r6 (with or without functions calling) stmfd!,,, r6, lr ldmfd!,,, r6, pc save data (,, r6 are used by function save) restore registers and return to caller Position of is not a standard r6 lr ARM: function prologue/epilogue ARM: function prologue/epilogue Stack allocation: local vars in r0- and on stmfd!,,, lr sub,, #4 add,, #4 ldmfd!,,, pc str lr, [, #-4]! ldr pc, [], #4 local-1 lr save data (, are used by function save) allocate room on (4 bytes in this example) unroll restore registers and return to caller Stack allocation (save lr only): local vars in r0-r3 another function is called save lr return to caller Stack allocation (save local registers, make room for other local variables, use the pointer) mov ip, stmfd!,,,, lr sub, ip, #0 sub,, #8 ( may change) add,, #8 ldmfd!,,,, pc ip can be used as a scratch register on function enter save current value of save data (, are used by function save) compute the - address allocate local variables restore registers local2 local1 : restore old pointer lrpc: return to caller

7 ARM: function prologue/epilogue Stack allocation (save local registers, make room for other local variables, use the pointer) mov ip, stmfd!,,,, lr sub, ip, #4 sub,, #8 ( may change) add,, #8 ldmfd!,,,, pc save current value of save data (, are used by function save) compute the - address allocate local variables restore registers : restore old pointer lrpc: return to caller ARM: function prologue/epilogue Stack allocation (save local registers, make room for other local variables, use the pointer) stmfd!,,,, lr add,, #16 sub,, #8 ( may change) add,, #8 ldmfd!,,,, pc save data (, are used by function save) compute the - address allocate local variables restore registers : restore old pointer lrpc: return to caller local2 local1 local2 local1 ip can be used as a scratch register on function enter Rules for can differ (e.g., point to the upper used location) Using : local variables are at fixed offsets from (local1: [-20] local2: [-24]) ARM: post/pre - increment/decrement MIPS Access with no pointer changes: ldr / ldrb / str / strb Rd, [Rs, #offset] Example: ldr R4, [R6, #20] -- R4 <= MEM[R6+20] Access with pre-change on pointer ldr / ldrb / str / strb Rd, [Rs, #offset]! Example: ldr R2, [R1, #4]! -- R1 <= R1+4 ; R2 <= MEM[R1] Access with post-change on pointer ldr / ldrb / str / strb Rd, [Rs], #offset increasing addresses outgoing arguments ptr to global data local vars saved registers input arguments arg 1 arg 2 arg 3 arg 4 arg 5 global ptr local 1 local 2 s0-s7 ra arg 1 arg 2 (after allocation) (on entry) The must be 8-byte aligned can be used as pointer. Outgoing args (if needed): args passed in registers are not written on by the caller (but room is allocated). Ptr to global: not mandatory if not changed Space for local vars is 8-byte aligned Space for saved registers is 8-byte aligned Other blocks can be 8-byte aligned (not mandatory) Space for s0-s7 must be reserved and used only for registers actually modified. ra must be saved for non-leaf functions. Example: ldrb R7, [R0], #4 -- R7(lsb) <= MEM[R0] ; R0 <= R0+4 Position of is not a standard.

8 MIPS: function prologue/epilogue MIPS: function prologue/epilogue No allocation: local vars in $t0-$t9 (and $a0-$a3, $v0, $v1) - no other functions called return to caller Stack allocation (to save local registers): a local var in $s0 - no other functions called Stack allocation: other functions called subu $,$,24 sw $ra,20($) lw $ra,20($) addu $,$,24 allocate (8-byte aligned) save $ra restore $ra return to caller and restore $ Stack allocation: save a local register ($s0) - other functions called arg 1 arg 2 arg 3 arg 4 $ra subu $,$,8 sw $s0,4($) lw $s0,4($) addu $,$,8 allocate (8-byte aligned) save $s0 restore registers return to caller and restore $ padding $s0 subu $,$,24 sw $ra,20($) sw $s0,16($) lw $ra,20($) lw $s0,26($) addu $,$,24 allocate (8-byte aligned) save registers restore registers return to caller and restore $ arg 1 arg 2 arg 3 arg 4 $s0 $ra MIPS: function prologue/epilogue MIPS: memory access Stack allocation: save a local register ($s0) use locals on - other functions called subu $,$,32 sw $ra,28($) sw $s0,24($) local_var is 24($) lw $ra,28($) lw $s0,24($) addu $,$,32 using a pointer: subu $,$,40 sw $,32($) move $,$ sw $ra,36($) sw $s0,28($) local_var is 20($) lw $ra,36($) lw $,32($) lw $s0,28($) addu $,$,40 allocate (8-byte aligned) save registers restore registers return to caller and restore $ allocate and set ptr save registers restore registers return to caller and restore $ arg 1 arg 2 arg 3 arg 4 local_var $s0 $ra arg 1 arg 2 arg 3 arg 4 local_var $s0 $ $ra lw / lb / sw / sb $Rd, offset($rs) Examples: lw $a0, 12($a4) -- $a0 <= MEM[$a4+12] lb $a3, 0($a2) -- $a3(lsb) <= MEM[$a2] sw $v1, 4($t0) -- MEM[$t0+4] <= $v1 A cycle delay is needed before loaded data are ready (use to avoid hazards)

9 strcpy: C strcpy: ARM assembly void my_strcpy(char *dest, char *src) while (*src) *(dest++) = *(src++); *dest=0; on function entry: r0 = dest r1 = src on function entry: r0 = dest r1 = src setup local_1 <= r0 [dest] local_2 <= r1 [src] if (*local_2 == 0) goto endloop *local_1 <= *local_2 local_1++ local_2++ goto loop end *local_1 <= 0 return (restore ) setup local_1 <- r0 local_2 <- r1 r1 <- local_2 ; r2 <- MEM[r1] ; if (r2== 0) goto endloop r1 <- local_1 ; r2 <- local_2 ; r3 <- MEM[r2] ; MEM[r1] <- r3 r1++ ; local_1 <- r1 ; r2++ ; local_2 <- r2 goto loop end r1 <-local_1 ; r2 <- 0 ; MEM[r1] <- r2 return (restore ) strcpy: ARM assembly strcpy: ARM assembly using local vars allocate choice: use pointer save on : ( pointer of caller) lr return address (not really needed, since there are no function calls) allocate on : local1 local2 stmfd!,, lr ; save on regs that will be modified add,, #8 ; compute (base of ) sub,, #8 ; reserve room on for local vars ; (8 bytes) ; local_1: MEM[-12] local_2: MEM[-16] str r0, [, #-12] ; local_1 <- dest (dest is in r0) str r1, [, #-16] ; local_2 <- src (src is in r1) ldr r1, [, #-16] ; r1 <- local_2 ldrb r2, [r1, #0] ; r2 <- *local_2 cmp r2, #0 ; compare *local_2 and 0 beq endloop ; jump to endloop label local2 local

10 strcpy: ARM assembly strcpy: ARM assembly (opt) ldr r2, [, #-16] ; r2 <- local_2 ldr r1, [, #-12] ; r1 <- local_1 ldrb r3, [r2, #0] ; r3 <- MEM[r2] (r3 <- *local_2 ; load only one byte) strb r3, [r1, #0] ; MEM[r1] <- r3 (*local_1 <- *local_2 ; write only one byte) add r1, r1, #1 ; r1 <- r1+1 (r1 <- local_1+1) str r1, [, #-12] ; local_1 <- r1 (update local_1) add r2, r2, #1 ; r2 <- r2+1 (r2 <- local_2+1) str r2, [, #-16] ; local_2 <- r2 (update local_2) b loop ; jump back to loop end ldr r1, [, #-12] ; r1 <- MEM[-12] (r1 <- local_1) mov r2, #0 ; r2 <- 0 strb r2, [r1, #0] ; MEM[r1] <- r2 (*local_1 <- 0) return: add,, #8 ; delete local vars ldmfd!,, pc ; restore registers from ; (pc is loaded with the previous value ; of lr) on function entry: r0 = dest r1 = src setup if (*r1 == 0) goto endloop r0++ <= r3 r3 <= *(++r1) if (r3!=0) goto loop end *r0 <= 0 return (restore ) on function entry: r0 = dest r1 = src setup r3 <- MEM[r1] ; if (r3 == 0) goto endloop MEM[r0++] <- r3 r3 <- MEM[++r1] if (r3!=0) goto loop end r3 <- 0 ; MEM[r0] <- r3 return (restore ) strcpy: ARM assembly (opt) strcpy: MIPS assembly ldrb r3, [r1, #0] ; r3 <- MEM[r1] (r3 <- *src) cmp r3, #0 ; compare *src and 0 beq endloop ; if r3==0 jump to endloop label strb r3, [r0], #1 ; MEM[r0] <- r3 ; r0 <- r0 + 1 (*(dest++) <-r3 ) ldrb r3, [r1, #1]! ; r3 <- MEM[r1+1] ; r1<-r1+1 (r3 <- *++src) cmp r3, #0 ; compare r3 and 0 bne loop ; if r3!= 0 jump back to loop label end strb r3, [r0, #0] ; MEM[r0] <- r3 (*dest <- 0; here, r3 contains 0) mov pc, lr ; return choice: save args on choice: use pointer save on : ( pointer of caller) save on : dest ($a0) src ($a1) no local vars, no function calls is not required function arguments dest src

11 strcpy: MIPS assembly strcpy: MIPS assembly subu $,$,8 ; reserve room on (8 bytes: and ra) sw $,0($) ; save move $,$ ; <- sw $a0,8($) ; save first function argument (in MEM[+8]) sw $a1,12($) ; save second function argument (in MEM[+12]) lw $v0,12($) ; v0 <- src ; wait for memory read lb $v1,0($v0) ; v1 <- *src ; wait for memory read beq $v1,$zero,endloop ; if v1==0 jump to endloop label ; delay slot (jump slot) saved registers function arguments ra dest src dest: +8 src: +12 lw $a0,12($) ; a0 <- src lw $v0,8($) ; v0 <- dest lbu $a3,0($a0) ; a3 <- *src (load one byte) sb $a3,0($v0) ; *dest <- a3 (*dest <- *src write one byte) addu $a0,$a0,1 ; a0 <- a0+1 sw $a0,12($) ; src <- a0 (src++) addu $v0,$v0,1 ; v0 <- v0+1 sw $v0,8($) ; dest <- v0 (dest++) j loop ; jump back to loop label end lw $v0,8($) ; v0 <- dest sb $zero,0($v0) ; *dest <- 0 return: move $,$ ; restore lw $,0($) ; restore from addu $,$,8 ; free memory used reserved for local variables ; return strcpy: MIPS assembly (opt) ARM: multiplication / division lb $v0,0($a1) ; v0 <- MEM[a1] (v0 <- *src) beq $v0,$zero,endloop ; if se v0==0 jump to endloop addu $a1,$a1,1 ; a1 <- a1+1 (src++) (use delay slot) sb $v0,0($a0) ; MEM[a0] <- v0 (*dest <- v0) j loop ; jump back to loop addu $a0,$a0,1 ; a0 <- a0+1 (dest++) (use delay slot) end ; return sb $zero,0($a0) ; *dest <- 0 (use delay slot) Multiplication: instruction mul mul R0, R1, R2 -- R0 <= R1*R2 Division/module: functions ( divsi3 and modsi3) res = divsi3(a,b) -- res <= a/b mov R0, dividend mov R0, dividend mov R1, divisor mov R1, divisor bl divsi3 bl modsi3 -- in R0 the division result -- in R0 the module

12 MIPS: multiplication / division factorial: C Multiplication: instruction mult 64-bit result in ecial registers hi and low mult $a0,$v1 mflo $a1 -- $a1 <= $a0 * $v1 (32 low bits) int factorial(int n) if (n<0) return 0; else if (n==0) return 1; else return n*factorial(n-1); Division/module: instruction div Division result in lo, module in hi div $t8,$t1 mflo $a1 -- $a1 <= $t8 / $t1 mfhi $a2 -- $a2 <= $t8 % $t1 factorial: ARM assembly factorial: MIPS assembly factorial: stmfd!,, lr ; save registers ( will be used) subs, r0, #0 ; <- r0-0 and set flags movlt r0, #0 ; if r0-0 < 0 (last operation that set flags) r0<-0 ldmltfd!,, pc ; if r0-0 < 0 (last operation that set flags) restore ; registers e return compute: beq return ; if r0-0 = 0 jump to return sub r0,, #1 ; r0 <- -1 (argument for the next ; function call) bl factorial ; recursive function call mul r0,, r0 ; r0 <- r0 (compute the result to return) ldmfd!,, pc ; restore registers and return return: mov r0, #1 ; r0 <- 1 ldmfd!,, pc ; restore registers and return factorial: subu $,$,24 ; reserve room ; (memory for ra, s0, arguments for called f [4 word]) function arguments n arguments for called function saved registers function arguments n s0 ra n

13 factorial: MIPS assembly Mul: C factorial: subu $,$,24 ; reserve (room for ra, s0, args [4 word]) sw $s0,16($) ; save s0 (will be used) move $s0,$a0 ; s0 <- a0 (s0 <- n) bgez $s0,compute ; if s0>=0 jump to compute sw $ra,20($) ; save return address (use delay slot) j return ; jump to return move $v0,$zero ; v0 <- 0 (use delay slot) compute: beq $s0,$zero,return ; if s0==zero jump to return li $v0,1 ; v0 <- 1 (use delay slot) jal factorial ; recursive function call addu $a0,$s0,-1 ; a0 <- s0-1 (argument for the recursive function call) ; (use delay slot) mult $s0,$v0 ; <hi,lo> <- s0 v0 (hi e lo: ecial registers) mflo $v0 ; v0 <- lo return: lw $ra,20($) ; restore ra lw $s0,16($) ; restore s0 ; return addu $,$,24 ; free allocated ace ; (use delay slot) int Mul(unsigned int a, unsigned int b) if (b==0) return 0; else if (b==1) return a; else return a+mul(a,b-1); Mul: ARM assembly Mul: MIPS assembly Mul: stmfd!,, lr mov, r0 ; save r0 (r0 will be written by the recursive call) cmp r1, #0 ; b ==0? moveq r0, r1 ; return 0 ldmeqfd!,, pc cmp r1, #1 ; b==1? beq return ; return a (a is still in r0) sub r1, r1, #1 bl Mul ; r0 = Mul(a,b-1) add r0,, r0 ; r0 = r0+a return: ldmfd!,, pc ; return Mul: subu $,$,24 sw $s0,16($) move $s0,$a0 ; save a0 (a0 will be overwritten by the recursive call) sw $ra,20($) beq $a1,$zero,return ; b ==0? move $v0,$zero ; return 0 (use delay slot) li $v0,1 beq $a1,$v0,label ; b ==1? move $a0,$s0 ; return a (a is in s0) (use delay slot) jal Mul addu $a1,$a1,-1 ; v0 = Mul(a,b-1) (use delay slot) j return addu $v0,$s0,$v0 ; compute the return value: a+v0 (use delay slot) label: move $v0,$s0 return: lw $ra,20($) lw $s0,16($) addu $,$,24

14 mcd: C mcd: ARM assembly int mcd(int a, int b) if (b==0) return a; if (a>b) return mcd(b, a%b); else return mcd(a, b%a); tail-end recursion: can easily become a loop mcd: label: stmfd!,,, lr mov, r0 mov, r1 cmp, #0 moveq r0, ldmeqfd!,,, pc ; b==0? return a cmp, ; set flags movgt r0, movgt r1, movle r0, movle r1, ; r0=max(,) r1=min(,) movgt, ; =min(,) (for next computation iterations) bl modsi3 ; r0 = r0 % r1 mov, r0 ; = r0 % r1 b label ; recursion (with no function call: tail end recursion) ; loop computes mcd(,) Note: the library function " modsi3" computes the remainder between its two arguments mcd: MIPS assembly Reversing mcd_ricor: label_3: bne $a1,$zero,label_1 slt $v0,$a1,$a0 move $v0,$a0 label_1: beq $v0,$zero,label_2 div $zero,$a0,$a1 mfhi $v0 move $a0,$a1 j label_3 move $a1,$v0 ; a0=b; a1=a%b label_2: ; a1>=a0 div $zero,$a1,$a0 mfhi $v0 j label_3 move $a1,$v0 ; a0=a; a1=b%a Notes: 1. when a division is performed, the quotient is stored into the ecial register lo and the remainder is stored into the ecial register hi 2. the instruction mfhi loads the content of hi into the indicated general purpose register To inect: unkwnown1 ARM assembly unkwnown2 MIPS assembly

15 ?: ARM assembly?: MIPS assembly unknown1: ldrb r2, [r0], #1 ldrb r3, [r1], #1 cmp r2, #0 beq label_1 cmp r2, r3 beq unknown1 mvnls r0, #0 // ls: comparison result is < (unsigned values) movhi r0, #1 // hi: comparison result is > (unsigned values) mov pc, lr label_1: mvn r0, #0 // mvn: mov negated (mov r0, not #0) cmp r3, #0 moveq r0, #0 mov pc, lr unknown2: move $v0,$zero lbu $v1,0($a0) beq $v1,$zero,label_3 andi $a1,$a1,0x00ff label_1: bne $v1,$a1,label_2 addu $v0,$v0,1 label_2: addu $a0,$a0,1 lbu $v1,0($a0) bne $v1,$zero,label_1 label_3:

ARM Assembly Language. Programming

ARM Assembly Language. Programming Outline: ARM Assembly Language the ARM instruction set writing simple programs examples Programming hands-on: writing simple ARM assembly programs 2005 PEVE IT Unit ARM System Design ARM assembly language

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

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

Compiling Techniques

Compiling Techniques Lecture 10: An Introduction to MIPS assembly 18 October 2016 Table of contents 1 Overview 2 3 Assembly program template.data Data segment: constant and variable definitions go here (including statically

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

Computer Architecture. The Language of the Machine

Computer Architecture. The Language of the Machine Computer Architecture The Language of the Machine Instruction Sets Basic ISA Classes, Addressing, Format Administrative Matters Operations, Branching, Calling conventions Break Organization All computers

More information

The MIPS Instruction Set Architecture

The MIPS Instruction Set Architecture The MIPS Set Architecture CPS 14 Lecture 5 Today s Lecture Admin HW #1 is due HW #2 assigned Outline Review A specific ISA, we ll use it throughout semester, very similar to the NiosII ISA (we will use

More information

ARM Instruction Set. Computer Organization and Assembly Languages Yung-Yu Chuang. with slides by Peng-Sheng Chen

ARM Instruction Set. Computer Organization and Assembly Languages Yung-Yu Chuang. with slides by Peng-Sheng Chen ARM Instruction Set Computer Organization and Assembly Languages g Yung-Yu Chuang with slides by Peng-Sheng Chen Introduction The ARM processor is easy to program at the assembly level. (It is a RISC)

More information

ARM Instruction Set. Introduction. Memory system. ARM programmer model. The ARM processor is easy to program at the

ARM Instruction Set. Introduction. Memory system. ARM programmer model. The ARM processor is easy to program at the Introduction ARM Instruction Set The ARM processor is easy to program at the assembly level. (It is a RISC) We will learn ARM assembly programming at the user level l and run it on a GBA emulator. Computer

More information

Outline. ARM Introduction & Instruction Set Architecture. ARM History. ARM s visible registers

Outline. ARM Introduction & Instruction Set Architecture. ARM History. ARM s visible registers Outline ARM Introduction & Instruction Set Architecture Aleksandar Milenkovic E-mail: Web: milenka@ece.uah.edu http://www.ece.uah.edu/~milenka ARM Architecture ARM Organization and Implementation ARM Instruction

More information

Multiple data transfer instructions

Multiple data transfer instructions Multiple data transfer instructions ARM also supports multiple loads and stores: When the data to be copied to the stack is known to be a multiple of 4 bytes, copying is faster using load multiple and

More information

SPIM Instruction Set

SPIM Instruction Set SPIM Instruction Set This document gives an overview of the more common instructions used in the SPIM simulator. Overview The SPIM simulator implements the full MIPS instruction set, as well as a large

More information

101 Assembly. ENGR 3410 Computer Architecture Mark L. Chang Fall 2009

101 Assembly. ENGR 3410 Computer Architecture Mark L. Chang Fall 2009 101 Assembly ENGR 3410 Computer Architecture Mark L. Chang Fall 2009 What is assembly? 79 Why are we learning assembly now? 80 Assembly Language Readings: Chapter 2 (2.1-2.6, 2.8, 2.9, 2.13, 2.15), Appendix

More information

MNEMONIC OPERATION ADDRESS / OPERAND MODES FLAGS SET WITH S suffix ADC

MNEMONIC OPERATION ADDRESS / OPERAND MODES FLAGS SET WITH S suffix ADC ECE425 MNEMONIC TABLE MNEMONIC OPERATION ADDRESS / OPERAND MODES FLAGS SET WITH S suffix ADC Adds operands and Carry flag and places value in destination register ADD Adds operands and places value in

More information

ARM Assembly Language

ARM Assembly Language ARM Assembly Language Introduction to ARM Basic Instruction Set Microprocessors and Microcontrollers Course Isfahan University of Technology, Dec. 2010 1 Main References The ARM Architecture Presentation

More information

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

ECE232: Hardware Organization and Design. Computer Organization - Previously covered ECE232: Hardware Organization and Design Part 6: MIPS Instructions II http://www.ecs.umass.edu/ece/ece232/ Adapted from Computer Organization and Design, Patterson & Hennessy, UCB Computer Organization

More information

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture ECE468 Computer Organization & Architecture MIPS Instruction Set Architecture ECE468 Lec4.1 MIPS R2000 / R3000 Registers 32-bit machine --> Programmable storage 2^32 x bytes 31 x 32-bit GPRs (R0 = 0) 32

More information

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2) Introduction to the MIPS ISA Overview Remember that the machine only understands very basic instructions (machine instructions) It is the compiler s job to translate your high-level (e.g. C program) into

More information

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook) Lecture 2 Instructions: Language of the Computer (Chapter 2 of the textbook) Instructions: tell computers what to do Chapter 2 Instructions: Language of the Computer 2 Introduction Chapter 2.1 Chapter

More information

MIPS Instruction Set

MIPS Instruction Set MIPS Instruction Set Prof. James L. Frankel Harvard University Version of 7:12 PM 3-Apr-2018 Copyright 2018, 2017, 2016, 201 James L. Frankel. All rights reserved. CPU Overview CPU is an acronym for Central

More information

Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )

Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont ) Chapter 2 Computer Abstractions and Technology Lesson 4: MIPS (cont ) Logical Operations Instructions for bitwise manipulation Operation C Java MIPS Shift left >>> srl Bitwise

More information

ARM Assembly Programming

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

More information

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: MIPS Programming

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: MIPS Programming Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring 2009 Topic Notes: MIPS Programming We spent some time looking at the MIPS Instruction Set Architecture. We will now consider

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

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

MIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support

MIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support Components of an ISA EE 357 Unit 11 MIPS ISA 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support SUBtract instruc. vs. NEGate + ADD instrucs. 3. Registers accessible

More information

ARM Assembly Programming

ARM Assembly Programming ARM Assembly Programming Computer Organization and Assembly Languages g Yung-Yu Chuang with slides by Peng-Sheng Chen GNU compiler and binutils HAM uses GNU compiler and binutils gcc: GNU C compiler as:

More information

Reduced Instruction Set Computer (RISC)

Reduced Instruction Set Computer (RISC) Reduced Instruction Set Computer (RISC) Reduced Instruction Set Computer (RISC) Focuses on reducing the number and complexity of instructions of the machine. Reduced number of cycles needed per instruction.

More information

Reduced Instruction Set Computer (RISC)

Reduced Instruction Set Computer (RISC) Reduced Instruction Set Computer (RISC) Focuses on reducing the number and complexity of instructions of the ISA. RISC Goals RISC: Simplify ISA Simplify CPU Design Better CPU Performance Motivated by simplifying

More information

Computer Architecture. MIPS Instruction Set Architecture

Computer Architecture. MIPS Instruction Set Architecture Computer Architecture MIPS Instruction Set Architecture Instruction Set Architecture An Abstract Data Type Objects Registers & Memory Operations Instructions Goal of Instruction Set Architecture Design

More information

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei Instruction Set Architecture part 1 (Introduction) Mehran Rezaei Overview Last Lecture s Review Execution Cycle Levels of Computer Languages Stored Program Computer/Instruction Execution Cycle SPIM, a

More information

MIPS Architecture and Assembly Language Overview

MIPS Architecture and Assembly Language Overview MIPS Architecture and Assembly Language Overview Adapted from: http://edge.mcs.dre.g.el.edu/gicl/people/sevy/architecture/mipsref(spim).html [Register Description] [I/O Description] Data Types and Literals

More information

ECE 15B Computer Organization Spring 2010

ECE 15B Computer Organization Spring 2010 ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 7: Procedures I Partially adapted from Computer Organization and Design, 4 th edition, Patterson and Hennessy, and classes taught by and

More information

CS 61c: Great Ideas in Computer Architecture

CS 61c: Great Ideas in Computer Architecture MIPS Functions July 1, 2014 Review I RISC Design Principles Smaller is faster: 32 registers, fewer instructions Keep it simple: rigid syntax, fixed instruction length MIPS Registers: $s0-$s7,$t0-$t9, $0

More information

MIPS Assembly Programming

MIPS Assembly Programming COMP 212 Computer Organization & Architecture COMP 212 Fall 2008 Lecture 8 Cache & Disk System Review MIPS Assembly Programming Comp 212 Computer Org & Arch 1 Z. Li, 2008 Comp 212 Computer Org & Arch 2

More information

Introduction to MIPS Processor

Introduction to MIPS Processor Introduction to MIPS Processor The processor we will be considering in this tutorial is the MIPS processor. The MIPS processor, designed in 1984 by researchers at Stanford University, is a RISC (Reduced

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

Lecture 5: Procedure Calls

Lecture 5: Procedure Calls Lecture 5: Procedure Calls Today s topics: Procedure calls and register saving conventions 1 Example Convert to assembly: while (save[i] == k) i += 1; i and k are in $s3 and $s5 and base of array save[]

More information

VE7104/INTRODUCTION TO EMBEDDED CONTROLLERS UNIT III ARM BASED MICROCONTROLLERS

VE7104/INTRODUCTION TO EMBEDDED CONTROLLERS UNIT III ARM BASED MICROCONTROLLERS VE7104/INTRODUCTION TO EMBEDDED CONTROLLERS UNIT III ARM BASED MICROCONTROLLERS Introduction to 32 bit Processors, ARM Architecture, ARM cortex M3, 32 bit ARM Instruction set, Thumb Instruction set, Exception

More information

M2 Instruction Set Architecture

M2 Instruction Set Architecture M2 Instruction Set Architecture Module Outline Addressing modes. Instruction classes. MIPS-I ISA. High level languages, Assembly languages and object code. Translating and starting a program. Subroutine

More information

ECE 30 Introduction to Computer Engineering

ECE 30 Introduction to Computer Engineering ECE 30 Introduction to Computer Engineering Study Problems, Set #3 Spring 2015 Use the MIPS assembly instructions listed below to solve the following problems. arithmetic add add sub subtract addi add

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

Thomas Polzer Institut für Technische Informatik

Thomas Polzer Institut für Technische Informatik Thomas Polzer tpolzer@ecs.tuwien.ac.at Institut für Technische Informatik Branch to a labeled instruction if a condition is true Otherwise, continue sequentially beq rs, rt, L1 if (rs == rt) branch to

More information

Support for high-level languages

Support for high-level languages Outline: Support for high-level languages memory organization ARM data types conditional statements & loop structures the ARM Procedure Call Standard hands-on: writing & debugging C programs 2005 PEVE

More information

Mark Redekopp, All rights reserved. EE 357 Unit 11 MIPS ISA

Mark Redekopp, All rights reserved. EE 357 Unit 11 MIPS ISA EE 357 Unit 11 MIPS ISA Components of an ISA 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support SUBtract instruc. vs. NEGate + ADD instrucs. 3. Registers accessible

More information

ECE232: Hardware Organization and Design

ECE232: Hardware Organization and Design ECE232: Hardware Organization and Design Lecture 6: Procedures Adapted from Computer Organization and Design, Patterson & Hennessy, UCB Overview Procedures have different names in different languages Java:

More information

ICS DEPARTMENT ICS 233 COMPUTER ARCHITECTURE & ASSEMBLY LANGUAGE. Midterm Exam. First Semester (141) Time: 1:00-3:30 PM. Student Name : _KEY

ICS DEPARTMENT ICS 233 COMPUTER ARCHITECTURE & ASSEMBLY LANGUAGE. Midterm Exam. First Semester (141) Time: 1:00-3:30 PM. Student Name : _KEY Page 1 of 14 Nov. 22, 2014 ICS DEPARTMENT ICS 233 COMPUTER ARCHITECTURE & ASSEMBLY LANGUAGE Midterm Exam First Semester (141) Time: 1:00-3:30 PM Student Name : _KEY Student ID. : Question Max Points Score

More information

We will study the MIPS assembly language as an exemplar of the concept.

We will study the MIPS assembly language as an exemplar of the concept. MIPS Assembly Language 1 We will study the MIPS assembly language as an exemplar of the concept. MIPS assembly instructions each consist of a single token specifying the command to be carried out, and

More information

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes Chapter 2 Instructions: Language of the Computer Adapted by Paulo Lopes Instruction Set The repertoire of instructions of a computer Different computers have different instruction sets But with many aspects

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

MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions

MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions Representing Instructions Instructions are encoded in binary Called machine code MIPS instructions Encoded as 32-bit instruction words Small number of formats encoding operation code (opcode), register

More information

Procedure Calls Main Procedure. MIPS Calling Convention. MIPS-specific info. Procedure Calls. MIPS-specific info who cares? Chapter 2.7 Appendix A.

Procedure Calls Main Procedure. MIPS Calling Convention. MIPS-specific info. Procedure Calls. MIPS-specific info who cares? Chapter 2.7 Appendix A. MIPS Calling Convention Chapter 2.7 Appendix A.6 Procedure Calls Main Procedure Call Procedure Call Procedure Procedure Calls Procedure must from any call Procedure uses that main was using We need a convention

More information

ARM-7 ADDRESSING MODES INSTRUCTION SET

ARM-7 ADDRESSING MODES INSTRUCTION SET ARM-7 ADDRESSING MODES INSTRUCTION SET Dr. P. H. Zope 1 Assistant Professor SSBT s COET Bambhori Jalgaon North Maharashtra University Jalgaon India phzope@gmail.com 9860631040 Addressing modes When accessing

More information

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture EEM 486: Computer Architecture Lecture 2 MIPS Instruction Set Architecture EEM 486 Overview Instruction Representation Big idea: stored program consequences of stored program Instructions as numbers Instruction

More information

MIPS Assembly Language

MIPS Assembly Language MIPS Assembly Language Chapter 15 S. Dandamudi Outline MIPS architecture Registers Addressing modes MIPS instruction set Instruction format Data transfer instructions Arithmetic instructions Logical/shift/rotate/compare

More information

Branch Instructions. R type: Cond

Branch Instructions. R type: Cond Branch Instructions Standard branch instructions, B and BL, change the PC based on the PCR. The next instruction s address is found by adding a 24-bit signed 2 s complement immediate value

More information

Review of Activation Frames. FP of caller Y X Return value A B C

Review of Activation Frames. FP of caller Y X Return value A B C Review of Activation Frames In general, activation frames are organized like this: HI LO Bookkeeping/preserved registers I/O parameters Locals and temps RA of caller FP of caller Y X Return value A B C

More information

Computer Architecture. Chapter 2-2. Instructions: Language of the Computer

Computer Architecture. Chapter 2-2. Instructions: Language of the Computer Computer Architecture Chapter 2-2 Instructions: Language of the Computer 1 Procedures A major program structuring mechanism Calling & returning from a procedure requires a protocol. The protocol is a sequence

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

Architecture II. Computer Systems Laboratory Sungkyunkwan University

Architecture II. Computer Systems Laboratory Sungkyunkwan University MIPS Instruction ti Set Architecture II Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Making Decisions (1) Conditional operations Branch to 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

2.7 Supporting Procedures in hardware. Why procedures or functions? Procedure calls

2.7 Supporting Procedures in hardware. Why procedures or functions? Procedure calls 2.7 Supporting Procedures in hardware Why procedures or functions? Procedure calls Caller: Callee: Proc save registers save more registers set up parameters do function call procedure set up results get

More information

CSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI.

CSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI. CSCI 402: Computer Architectures Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI Recall Big endian, little endian Memory alignment Unsigned

More information

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei Computer Architecture Instruction Set Architecture part 2 Mehran Rezaei Review Execution Cycle Levels of Computer Languages Stored Program Computer/Instruction Execution Cycle SPIM, a MIPS Interpreter

More information

MIPS Assembly Language. Today s Lecture

MIPS Assembly Language. Today s Lecture MIPS Assembly Language Computer Science 104 Lecture 6 Homework #2 Midterm I Feb 22 (in class closed book) Outline Assembly Programming Reading Chapter 2, Appendix B Today s Lecture 2 Review: A Program

More information

ARM Instruction Set Architecture. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

ARM Instruction Set Architecture. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University ARM Instruction Set Architecture Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Condition Field (1) Most ARM instructions can be conditionally

More information

Today s Lecture. MIPS Assembly Language. Review: What Must be Specified? Review: A Program. Review: MIPS Instruction Formats

Today s Lecture. MIPS Assembly Language. Review: What Must be Specified? Review: A Program. Review: MIPS Instruction Formats Today s Lecture Homework #2 Midterm I Feb 22 (in class closed book) MIPS Assembly Language Computer Science 14 Lecture 6 Outline Assembly Programming Reading Chapter 2, Appendix B 2 Review: A Program Review:

More information

EEM870 Embedded System and Experiment Lecture 4: ARM Instruction Sets

EEM870 Embedded System and Experiment Lecture 4: ARM Instruction Sets EEM870 Embedded System and Experiment Lecture 4 ARM Instruction Sets Wen-Yen Lin, Ph.D. Department of Electrical Engineering Chang Gung University Email wylin@mail.cgu.edu.tw March 2014 Introduction Embedded

More information

ECE 2035 Programming HW/SW Systems Fall problems, 7 pages Exam Two 23 October 2013

ECE 2035 Programming HW/SW Systems Fall problems, 7 pages Exam Two 23 October 2013 Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate

More information

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda MIPS ISA and MIPS Assembly CS301 Prof. Szajda Administrative HW #2 due Wednesday (9/11) at 5pm Lab #2 due Friday (9/13) 1:30pm Read Appendix B5, B6, B.9 and Chapter 2.5-2.9 (if you have not already done

More information

Procedure Calling. Procedure Calling. Register Usage. 25 September CSE2021 Computer Organization

Procedure Calling. Procedure Calling. Register Usage. 25 September CSE2021 Computer Organization CSE2021 Computer Organization Chapter 2: Part 2 Procedure Calling Procedure (function) performs a specific task and return results to caller. Supporting Procedures Procedure Calling Calling program place

More information

Review: MIPS Organization

Review: MIPS Organization 1 MIPS Arithmetic Review: MIPS Organization Processor Memory src1 addr 5 src2 addr 5 dst addr 5 write data Register File registers ($zero - $ra) bits src1 data src2 data read/write addr 1 1100 2 30 words

More information

ECE 331 Hardware Organization and Design. Professor Jay Taneja UMass ECE - Discussion 3 2/8/2018

ECE 331 Hardware Organization and Design. Professor Jay Taneja UMass ECE - Discussion 3 2/8/2018 ECE 331 Hardware Organization and Design Professor Jay Taneja UMass ECE - jtaneja@umass.edu Discussion 3 2/8/2018 Study Jams Leader: Chris Bartoli Tuesday 5:30-6:45pm Elab 325 Wednesday 8:30-9:45pm Elab

More information

Chapter 2A Instructions: Language of the Computer

Chapter 2A Instructions: Language of the Computer Chapter 2A Instructions: Language of the Computer Copyright 2009 Elsevier, Inc. All rights reserved. Instruction Set The repertoire of instructions of a computer Different computers have different instruction

More information

Mark Redekopp, All rights reserved. EE 352 Unit 6. Stack Frames Recursive Routines

Mark Redekopp, All rights reserved. EE 352 Unit 6. Stack Frames Recursive Routines EE 352 Unit 6 Stack Frames Recursive Routines Arguments and Return Values MIPS convention is to use certain registers for this task $a0 - $a3 used to pass up to 4 arguments. If more arguments, use the

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

Lecture 7: Procedures

Lecture 7: Procedures Lecture 7: Procedures CSE 30: Computer Organization and Systems Programming Winter 2010 Rajesh Gupta / Ryan Kastner Dept. of Computer Science and Engineering University of California, San Diego Outline

More information

ECE260: Fundamentals of Computer Engineering

ECE260: Fundamentals of Computer Engineering Accessing and Addressing Memory James Moscola Dept. of Engineering & Computer Science York College of Pennsylvania Based on Computer Organization and Design, 5th Edition by Patterson & Hennessy American

More information

ARM Instruction Set Dr. N. Mathivanan,

ARM Instruction Set Dr. N. Mathivanan, ARM Instruction Set Dr., Department of Instrumentation and Control Engineering Visiting Professor, National Institute of Technology, TRICHY, TAMIL NADU, INDIA Instruction Set Architecture Describes how

More information

MIPS Functions and the Runtime Stack

MIPS Functions and the Runtime Stack MIPS Functions and the Runtime Stack COE 301 Computer Organization Prof. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals Presentation Outline

More information

Procedure Call and Return Procedure call

Procedure Call and Return Procedure call Procedures int len(char *s) { for (int l=0; *s!= \0 ; s++) l++; main return l; } void reverse(char *s, char *r) { char *p, *t; int l = len(s); reverse(s,r) N/A *(r+l) = \0 ; reverse l--; for (p=s+l t=r;

More information

ARM Architecture and Instruction Set

ARM Architecture and Instruction Set AM Architecture and Instruction Set Ingo Sander ingo@imit.kth.se AM Microprocessor Core AM is a family of ISC architectures, which share the same design principles and a common instruction set AM does

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

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

Lec 10: Assembler. Announcements

Lec 10: Assembler. Announcements Lec 10: Assembler Kavita Bala CS 3410, Fall 2008 Computer Science Cornell University Announcements HW 2 is out Due Wed after Fall Break Robot-wide paths PA 1 is due next Wed Don t use incrementor 4 times

More information

EE 361 University of Hawaii Fall

EE 361 University of Hawaii Fall C functions Road Map Computation flow Implementation using MIPS instructions Useful new instructions Addressing modes Stack data structure 1 EE 361 University of Hawaii Implementation of C functions and

More information

Machine Instructions - II. Hwansoo Han

Machine Instructions - II. Hwansoo Han Machine Instructions - II Hwansoo Han Conditional Operations Instructions for making decisions Alter the control flow - change the next instruction to be executed Branch to a labeled instruction if a condition

More information

EE 109 Unit 13 MIPS Instruction Set. Instruction Set Architecture (ISA) Components of an ISA INSTRUCTION SET OVERVIEW

EE 109 Unit 13 MIPS Instruction Set. Instruction Set Architecture (ISA) Components of an ISA INSTRUCTION SET OVERVIEW 1 2 EE 109 Unit 13 MIPS Instruction Set Architecting a vocabulary for the HW INSTRUCTION SET OVERVIEW 3 4 Instruction Set Architecture (ISA) Defines the of the processor and memory system Instruction set

More information

Flow Control In Assembly

Flow Control In Assembly Chapters 6 Flow Control In Assembly Embedded Systems with ARM Cortext-M Updated: Monday, February 19, 2018 Overview: Flow Control Basics of Flowcharting If-then-else While loop For loop 2 Flowcharting

More information

CSc 256 Midterm (green) Fall 2018

CSc 256 Midterm (green) Fall 2018 CSc 256 Midterm (green) Fall 2018 NAME: Problem 1 (5 points): Suppose we are tracing a C/C++ program using a debugger such as gdb. The code showing all function calls looks like this: main() { bat(5);

More information

ECE/CS 314 Fall 2003 Homework 2 Solutions. Question 1

ECE/CS 314 Fall 2003 Homework 2 Solutions. Question 1 ECE/CS 314 Fall 2003 Homework 2 Solutions Question 1 /* Equivalent C code with no loops (goto instead) char* strchr(char* pcstring, char csearchchr) strchr_loop: if (!*pcstring) return 0; if (*pcstring

More information

STEVEN R. BAGLEY ARM: PROCESSING DATA

STEVEN R. BAGLEY ARM: PROCESSING DATA STEVEN R. BAGLEY ARM: PROCESSING DATA INTRODUCTION CPU gets instructions from the computer s memory Each instruction is encoded as a binary pattern (an opcode) Assembly language developed as a human readable

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

MIPS Instruction Reference

MIPS Instruction Reference Page 1 of 9 MIPS Instruction Reference This is a description of the MIPS instruction set, their meanings, syntax, semantics, and bit encodings. The syntax given for each instruction refers to the assembly

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

comp 180 Lecture 10 Outline of Lecture Procedure calls Saving and restoring registers Summary of MIPS instructions

comp 180 Lecture 10 Outline of Lecture Procedure calls Saving and restoring registers Summary of MIPS instructions Outline of Lecture Procedure calls Saving and restoring registers Summary of MIPS instructions Procedure Calls A procedure of a subroutine is like an agent which needs certain information to perform a

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #8: MIPS Procedures 2005-06-30 CS 61C L08 MIPS Procedures (1) Andy Carle Topic Outline Functions More Logical Operations CS 61C L08

More information

Instruction Set Design and Architecture

Instruction Set Design and Architecture Instruction Set Design and Architecture COE608: Computer Organization and Architecture Dr. Gul N. Khan http://www.ee.ryerson.ca/~gnkhan Electrical and Computer Engineering Ryerson University Overview Computer

More information

Writing ARM Assembly. Steven R. Bagley

Writing ARM Assembly. Steven R. Bagley Writing ARM Assembly Steven R. Bagley Hello World B main hello DEFB Hello World\n\0 goodbye DEFB Goodbye Universe\n\0 ALIGN main ADR R0, hello ; put address of hello string in R0 SWI 3 ; print it out ADR

More information