Loop Example. CMPE 325 Computer Architecture II. Loop Solution. Loops in C. Improved Loop Solution. Loop Efficiency. Assembly Language (cont)

Size: px
Start display at page:

Download "Loop Example. CMPE 325 Computer Architecture II. Loop Solution. Loops in C. Improved Loop Solution. Loop Efficiency. Assembly Language (cont)"

Transcription

1 CMPE 325 Computer rchitecture II Cem Ergün Eastern Mediterranean University ssembly Language (cont) Loop Example Consider the code where array is an integer array with 100 elements Loop: g = g + [i] i = i + j; if (i!= h) goto Loop: g: $s0 h: $s1 i: $s2 j: $s3 : $s4 CMPE 325 CH #3 Slide #2 Loop Solution Use a conditional test Loop: add $t0, $s2, $s2 add $t0, $t0, $t0 add $t1, $t0, $s4 lw $t2, 0($t1) add $s0, $s0, $t2 add $s2, $s2, $s3 bne $s2, $s1, Loop # $t0 = 2 * i # $t0 = 4 * i # $t1 = &([i]) # $t2 = [i] # g = g + [i] # i = i + j # goto Loop if i!=h This sequence is known as a basic block since it has one entrance and one exit Loops in C Consider a very similar case with while while ([i] == k) i = i + j; Use a similar loop as before Loop: add $t0, $s0, $s0 # $t0 = 2 * i add $t0, $t0, $t0 # $t0 = 4 * i add $t1, $t0, $s3 # $t1 = &([i]) lw $t2, 0($t1) # $t2 = [i] bne $t2, $s2, Exit # goto Exit if!= add $s0, $s0, $s1 # i = i + j j Loop # goto Loop Exit: What is wrong with this approach? CMPE 325 CH #3 Slide #3 CMPE 325 CH #3 Slide #4 Loop Efficiency Improved Loop Solution Code uses two branches/iteration: Cond? Body of loop Better structure: Body of loop Cond? Remove extra branch j Cond # goto Cond Loop: add $s0, $s0, $s1 # i = i + j Cond: add $t0, $s0, $s0 # $t0 = 2 * i add $t0, $t0, $t0 # $t0 = 4 * i add $t1, $t0, $s3 # $t1 = &([i]) lw $t2, 0($t1) # $t2 = [i] beq $t2, $s2, Loop # goto Loop if == Exit: Reduced loop from 7 to 6 instructions Even small improvements important if loop executes many times CMPE 325 CH #3 Slide #5 CMPE 325 CH #3 Slide #6 1

2 Other Comparisons Other conditional arithmetic operators are useful in evaluating conditional expressions using <, >, <=, >= Conditional expressions also useful in signed vs. unsigned integers (to be discussed later) Register is set to 1 when condition is met Consider the following code if (f < g) goto Less; MIPS Comparisons Instruction Example Meaning Comments set less than slt $1, $2, $3 $1 = ($2 < $3) comp less than signed set less than imm slti $1, $2, 100 $1 = ($2 < 100) comp w/const signed set less than uns sltu $1, $2, $3 $1 = ($2 < $3) comp < unsigned set l.t. imm. uns sltiu $1, $2, 100 $1 = ($2 < 100) comp < const unsigned Solution slt $t0, $s0, $s1 # $t0 = 1 if $s0 < $s1 bne $t0, $zero, Less # Goto Less if $t0!= 0 CMPE 325 CH #3 Slide #7 CMPE 325 CH #3 Slide #8 MIPS Jumps & Branches Instruction Example Meaning jump j L goto L jump register jr $1 goto value in $1 jump and link jal L goto L and set $ra jump and link register jalr $1 goto $1 and set $ra branch equal beq $1, $2, L if ($1 == $s2) goto L branch not eq bne $1, $2, L if ($1!= $2) goto L branch l.t. 0 bltz $1, L if ($1 < 0) goto L branch l.t./eq 0 blez $1, L if ($1 <= 0) goto L branch g.t. 0 bgtz $1, L if ($1 > 0) goto L branch g.t./eq 0 bgez $1, L if ($1 >= 0) goto L CMPE 325 CH #3 Slide #9 Simplicity Notice that there was no branch less than instruction for comparing two registers? The reason is that such an instruction would be too complicated and would force a longer clock cycle time Therefore, conditionals that are not comparing against zero take at least two instructions where the first is a set and the second is a conditional branch The MIPS assembler supports pseudoinstructions for such operators and automatically converts them to the appropriate sequence of MIPS instructions CMPE 325 CH #3 Slide #10 Pseudoinstructions ssembler expands pseudoinstructions move $t0, $t1 # Copy $t1 to $t0 add $t0, $zero, $t1 # ctual instruction Some pseudoinstructions need a temporary register Cannot use $t, $s, etc. since they may be in use The $at register is reserved for the assembler blt $t0, $t1, L1 # Goto L1 if $t0 < $t1 slt $at, $t0, $t1 # Set $at = 1 if $t0 < $t1 bne $at, $zero, L1 # Goto L1 if $at!= 0 Pseudoinstructions (cont) The pseudoinstruction load immediate (li) provides transfer of a 16-bit constant value to reg li $t0, imm # Copy 16bit imm. value to $t0 addi $t0, $zero, imm# ctual instruction Example: Write a MIPS code to load h lui $s0, # $s0 is set to h addi $s0, $s0, # fter addition h CMPE 325 CH #3 Slide #11 CMPE 325 CH #3 Slide #12 2

3 Logical Operators Bitwise operators often useful for converting &&,, and! symbols into assembly lways operate unsigned (more later) MIPS Logical Instructions Instruction Example Meaning Comments and and $1, $2, $3 $1 = $2 & $3 Logical ND or or $1, $2, $3 $1 = $2 $3 Logical OR xor xor $1, $2, $3 $1 = $2 $3 Logical XOR nor nor $1, $2, $3 $1 = ~($2 $3) Logical NOR and immediate andi $1, $2, 10 $1 = $2 & 10 Logical ND w. constant or immediate ori $1, $2, 10 $1 = $2 10 Logical OR w. constant xor immediate xori $1, $2, 10 $1 = ~$2 & ~10 Logical XOR w. constant shift left log sll $1, $2, 10 $1 = $2 << 10 Shift left by constant shift right log srl $1, $2, 10 $1 = $2 >> 10 Shift right by constant shift right arith sra $1, $2, 10 $1 = $2 >> 10 Shift right (sign extend) shift left log var sllv $1, $2, $3 $1 = $2 << $3 Shift left by variable shift right log var srlv $1, $2, $3 $1 = $2 >> $3 Shift right by variable shift right arith srav $1, $2, $3 $1 = $2 >> $3 Shift right arith. by var load upper imm lui $1, 40 $1 = 40 << 16 Places imm in upper 16b CMPE 325 CH #3 Slide #13 CMPE 325 CH #3 Slide #14 Handling Procedures Procedures are useful for decomposing applications into smaller units Implementing procedures in assembly requires several things to be done Space must be set aside for local variables rguments must be passed in and return values passed out Execution must continue after the call Procedure Steps 1. Place parameters in a place where the procedure can access them 2. Transfer control to the procedure 3. cquire the storage resources needed for the procedure 4. Perform the desired task 5. Place the result value in a place where the calling program can access it 6. Return control to the point of origin CMPE 325 CH #3 Slide #15 CMPE 325 CH #3 Slide #16 Stacks Stacks are a natural way to temporarily store data for procedures (as well as call/return information) since they have a LIFO behavior Data is pushed onto the stack to store it and popped from the stack when not longer needed Implementation Common rules across procedures required Recent machines are set by software convention and earlier machines by hardware instructions Using Stacks Stacks can grown up or down Stack grows down in MIPS Entire stack frame is pushed and popped, rather than single elements CMPE 325 CH #3 Slide #17 CMPE 325 CH #3 Slide #18 3

4 Calling a Procedure To jump to a procedure, use the jal jump-andlink instruction jal tartget # Jump and link to label Saves the address of the next location into to register-31 and Jumps to the specified 26-bit local word address jal and jr Instructions jal Prod_ddr (J-Type) first increments the program counter (PC PC+4), 3 Prod_ddr/4 so that it points to the next location, then it stores that value into $ra (= $31). jr $ra (R-Type) copies $ra into PC, PC $ra causes to jump back to the stored return address. CMPE 325 CH #3 Slide #19 CMPE 325 CH #3 Slide #20 Who saves the register? Caller save ll values that have to be kept must be saved before a procedure is called. Callee save Within the procedure all used registers are saved and afterwards restored. rgument Passing Convention Return value is transferred in $v0 $v1. ($v0 and $v1) corresponds to ($2 and $3) Integer arguments up to four are passed in registers $a0 $a3. (= $4 $7). ny higher data structure is passed by a pointer. If there are more than 4 parameters, first four parameters are passed in registers, the others are transferred in the stack CMPE 325 CH #3 Slide #21 CMPE 325 CH #3 Slide #22 Register Saving Conventions Save the registers saved-registers s0 s7, arguments a0 a3, and system registers $gp, $sp, $fp and $ra before they are corrupted in a call. Restore them before the start of calling code. Procedure Coding Example The C code for swap procedure is: swap(int v[ ], int k) int temp; temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; Code it in MIPS ssembly. CMPE 325 CH #3 Slide #23 CMPE 325 CH #3 Slide #24 4

5 Coding Example -swap llocate registers to procedure variables. swap(int v[], int k) two arguments pointer v[ ] in $a0, integer k in $a1. $t0, $t1, for temp. values and addresses Write MIPS code for the procedure body. swap(int v[ ], int k) int temp; temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; sll $t1, $a1, 2 # $t1 k 4 add $t1, $a0, $t1 # $t1 v+(k 4) lw $t0, 0($t1) # $t0 = v[k] lw $t2, 4($t1) # $t2 = v[k+1] sw $t2, 0($t1) # v[k] $t2 ( = v[k+1] ) sw $t0, 4($t1) # v[k+1] $t0 (= v[k] ) Nothing to save since only temp.regs corrupted. none of $s0 $s7, $a0 $a3, $sp, $ra is corrupted CMPE 325 CH #3 Slide #25 Swap in Final Form Final form of the procedure swap: sll $t1, $a1, 2 # $t1 k 4 add $t1, $a0, $t1 # $t1 v+(k 4) lw $t0, 0($t1) # $t0 = v[k] lw $t2, 4($t1) # $t2 = v[k+1] sw $t2, 0($t1) # v[k] $t2 ( = v[k+1] ) sw $t0, 4($t1) # v[k+1] $t0 (= v[k] ) jr $ra Label to call the procedure return to caller code CMPE 325 CH #3 Slide #26 Nested Calls call in another call corrupts $ra. $ra must be saved on the stack before the second call and then restored after the return from the inner call. Nested Stacks The stack grows and shrinks downward : CLL B B: CLL C C: RET RET B C B B CMPE 325 CH #3 Slide #27 CMPE 325 CH #3 Slide #28 Coding Example: Procedures ssume x[ ] starts from and y[ ] starts from Code the following program in MIPS ssembler starting main from address 300, and f from 400. Main pocedure j=5 f(j,x); x[3]+=5; f procedure void f(int j, int x[]) if (j= =7) x[2]=6*x[1] x[0]; else g(y); g procedure int g(int y[]) int i; for (i=2;i<12;i++) y[i]*=2; y[2] = 4; Coding Example Main Body Main pocedure j=5 f(j,x); x[3]+=5; allocate registers two arguments in f(), use $a0, $a1 one argument in g() use $a0 j and x are saved variables in g(), i is local, temporary variable. address calculations in temp.registers. Code for Main Main:... li $a0,5 li $a1,10000 jal f lw $t0,12($a1) # $t0 x[3] addi $t0,$t0,5 # $10 x[3] + 5 sw $t0,12($a1) # x[3] x[3] + 5 CMPE 325 CH #3 Slide #29 CMPE 325 CH #3 Slide #30 5

6 Coding Example - Procedure f() f procedure void f(int j, int x[]) if (j= =7) x[2]=6*x[1] x[0]; else g(y); 2-words = 8 bytes $a0 is corrupted $ra is corrupted f: addi $sp,$sp, -8 sw $a0, 0($sp) sw $ra, 4($sp) label of procedure Callee saves the registers li $t0,7 # if (j!=7 ) bne $a0, $t0, Else # go to Else. li $t1, 6 # $t1 6, lw $t2, 4($a1) # $t2 x[1] mult $t2, $t1 # LO 6 x[1] mflo $t2 # $t2 6 x[1] lw $t1, 0($a1) # $t1 x[0] sub $t1, $t2, $t1 # $t1 6 x[1] x[0]; sw $t1, 8($a1) # x[2] 6 x[1] x[0]; j ExitIf Else: li $a0, jal g ExitIf: Callee restores the registers lw $a0, 0($sp) lw $ra, 4($sp) addi $sp,$sp, 8 return of procedure f() jr $ra CMPE 325 CH #3 Slide #31 g() procedure void g(int y[]) int i; for (i=2;i<12;i++) y[i]*=2; y[2] = 4; Only temporary registers are used No registers need to be saved. Coding Example Procedure g() g: li $t0, 2 # $10= i 2 for loop Loop: slti $t1, $t0, 12 # if ( i < 12) then $t1 1 beq $t1,$0, ExitF # if ($t1=0) exit for-loop. sll $t2, $t0, 2 # $t2 4 i add $t2, $a0, $t2 # $t2 y[] + 4 i lw $t3, 0($t2) # $t3 y[i] add $t3, $t3,$t3 # $t3 2 y[i] sw $t3, 0($t2) # y[i] 2 y[i] addi $t0, $t0, 1 # $t0 = i i+1 j Loop # loop again ExitF: # end of for loop lw $t3, 8($a0) addi $t3, $t3, 4 # $t3 # $t3 y[2] y[2] 4 sw $t3, 8($a0) # y[2] y[2] 4 jr $31 CMPE 325 CH #3 Slide #32 Decimal Coding of a Program coding starts from memory address 300 ten. memory word contents (instruction fields) address assembly with assembly without opc rs rt rd sa fn pseudocode pseudocode 300: li $a0,5 add $4,$0,5 304: li $a1,10000 add $5,$0, : jal f jal f 312: lw $t0,12($a1) lw $8,12($5) 316: addi $t0,$t0,5 addi $8,$8,5 320: sw $t0,12($a1) sw $8,12($5). F: 400: addi $sp,$sp, 8 addi $29,$29, 8 404: sw $a0,0($sp) sw $4,0($29) 408: sw $ra,4($sp) sw $31,4($29) 412: li $t0,7 addi $8,7 416: bne $4,$t0,Else bne $4,$8,Else 420: li $t1,6 addi $9,$0,6 424: lw $t2,4($a1) lw $10,4($5) 428: mult $t2,$t1 mult $10,$9 432: mflo $t2 mflo $10 436: lw $t1,0($a1) lw $9,0($5) 440: sub $t1,$t2,$t1 sub $9,$10,$9 444: sw $t1,8($a1) sw $9,8($5) 448: j ExitIf j ExitIf Else: 452: li $a0,20000 addi $4,$0, : jal G jal G ExitIf: 460: lw $a0,0($sp) lw $4,0($29) 464: lw $ra,4($sp) lw $31,4($29) 468: addi $sp,$sp,8 addi $29,$29,24 472: jr $ra jr $31 100= 400/4 8= ( )/4 115= 460/4 119= 476/4 CMPE 325 CH #3 Slide #33 Decimal Coding of a Program-2 continuation of coding memory word contents (instruction fields) address opc rs rt rd sa fn assembly with pseudocode g: 476: li $t0,2 Loop: 480: slti $t1,$t0,12 484: beq $t1,$0, ExitF 488: sll $t2,$t0,2 492: add $t2,$t2,$a0 496: lw $t3,0($t2) 500: add $t3,$t3,$t3 504: sw $t3,0($t2) 508: addi $t0,$t0,1 512: j Loop ExitF: 516: lw $t3, 8($a0) 520: addi $t3,$t3, 4 524: sw $t3, 8($a0) 528: jr $ra assembly without pseudocode addi $8,$0, 2 slti $9,$8,12 beq $9,$0, ExitF sll $10,$8,2 add $t2,$t2,$4 lw $11,0($10) add $11,$11,$11 sw $11,0($10) addi $8,$8,1 j Loop lw $11, 8($4) addi $11,$11, 4 sw $11, 8($4) jr $ =( )/4 120 =480/4 CMPE 325 CH #3 Slide #34 6

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

Translating C code to MIPS

Translating C code to MIPS Translating C code to MIPS why do it C is relatively simple, close to the machine C can act as pseudocode for assembler program gives some insight into what compiler needs to do what's under the hood do

More information

Instruction Set Architecture. or How to talk to computers if you aren t in Star Trek

Instruction Set Architecture. or How to talk to computers if you aren t in Star Trek Instruction Set Architecture or How to talk to computers if you aren t in Star Trek The Instruction Set Architecture Application Compiler Instr. Set Proc. Operating System I/O system Instruction Set Architecture

More information

Computer Systems Architecture

Computer Systems Architecture Computer Systems Architecture http://cs.nott.ac.uk/ txa/g51csa/ Thorsten Altenkirch and Liyang Hu School of Computer Science University of Nottingham Lecture 10: MIPS Procedure Calling Convention and Recursion

More information

MIPS Assembly Code Layout

MIPS Assembly Code Layout Learning MIPS & SPIM MIPS assembly is a low-level programming language The best way to learn any programming language is to write code We will get you started by going through a few example programs and

More information

Instruction Set Architecture

Instruction Set Architecture Instruction Set Architecture Consider x := y+z. (x, y, z are memory variables) 1-address instructions 2-address instructions LOAD y (r :=y) ADD y,z (y := y+z) ADD z (r:=r+z) MOVE x,y (x := y) STORE x (x:=r)

More information

Typy danych. Data types: Literals:

Typy danych. Data types: Literals: Lab 10 MIPS32 Typy danych Data types: Instructions are all 32 bits byte(8 bits), halfword (2 bytes), word (4 bytes) a character requires 1 byte of storage an integer requires 1 word (4 bytes) of storage

More information

COMP 303 MIPS Processor Design Project 4: MIPS Processor Due Date: 11 December 2009 23:59

COMP 303 MIPS Processor Design Project 4: MIPS Processor Due Date: 11 December 2009 23:59 COMP 303 MIPS Processor Design Project 4: MIPS Processor Due Date: 11 December 2009 23:59 Overview: In the first projects for COMP 303, you will design and implement a subset of the MIPS32 architecture

More information

Introduction to MIPS Assembly Programming

Introduction to MIPS Assembly Programming 1 / 26 Introduction to MIPS Assembly Programming January 23 25, 2013 2 / 26 Outline Overview of assembly programming MARS tutorial MIPS assembly syntax Role of pseudocode Some simple instructions Integer

More information

Stack machines The MIPS assembly language A simple source language Stack-machine implementation of the simple language Readings: 9.1-9.

Stack machines The MIPS assembly language A simple source language Stack-machine implementation of the simple language Readings: 9.1-9. Code Generation I Stack machines The MIPS assembly language A simple source language Stack-machine implementation of the simple language Readings: 9.1-9.7 Stack Machines A simple evaluation model No variables

More information

More MIPS: Recursion. Computer Science 104 Lecture 9

More MIPS: Recursion. Computer Science 104 Lecture 9 More MIPS: Recursion Computer Science 104 Lecture 9 Admin Homework Homework 1: graded. 50% As, 27% Bs Homework 2: Due Wed Midterm 1 This Wed 1 page of notes 2 Last time What did we do last time? 3 Last

More information

MIPS Assembler and Simulator

MIPS Assembler and Simulator MIPS Assembler and Simulator Reference Manual Last Updated, December 1, 2005 Xavier Perséguers (ing. info. dipl. EPF) Swiss Federal Institude of Technology xavier.perseguers@a3.epfl.ch Preface MIPS Assembler

More information

Review: MIPS Addressing Modes/Instruction Formats

Review: MIPS Addressing Modes/Instruction Formats Review: Addressing Modes Addressing mode Example Meaning Register Add R4,R3 R4 R4+R3 Immediate Add R4,#3 R4 R4+3 Displacement Add R4,1(R1) R4 R4+Mem[1+R1] Register indirect Add R4,(R1) R4 R4+Mem[R1] Indexed

More information

5 MIPS Assembly Language

5 MIPS Assembly Language 103 5 MIPS Assembly Language Today, digital computers are almost exclusively programmed using high-level programming languages (PLs), eg, C, C++, Java The CPU fetch execute cycle, however, is not prepared

More information

Winter 2002 MID-SESSION TEST Friday, March 1 6:30 to 8:00pm

Winter 2002 MID-SESSION TEST Friday, March 1 6:30 to 8:00pm University of Calgary Department of Electrical and Computer Engineering ENCM 369: Computer Organization Instructors: Dr. S. A. Norman (L01) and Dr. S. Yanushkevich (L02) Winter 2002 MID-SESSION TEST Friday,

More information

Lecture Outline. Stack machines The MIPS assembly language. Code Generation (I)

Lecture Outline. Stack machines The MIPS assembly language. Code Generation (I) Lecture Outline Code Generation (I) Stack machines The MIPS assembl language Adapted from Lectures b Profs. Ale Aiken and George Necula (UCB) A simple source language Stack- machine implementation of the

More information

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc Other architectures Example. Accumulator-based machines A single register, called the accumulator, stores the operand before the operation, and stores the result after the operation. Load x # into acc

More information

Assembly Language Programming

Assembly Language Programming Assembly Language Programming Assemblers were the first programs to assist in programming. The idea of the assembler is simple: represent each computer instruction with an acronym (group of letters). Eg:

More information

CSE 141 Introduction to Computer Architecture Summer Session I, 2005. Lecture 1 Introduction. Pramod V. Argade June 27, 2005

CSE 141 Introduction to Computer Architecture Summer Session I, 2005. Lecture 1 Introduction. Pramod V. Argade June 27, 2005 CSE 141 Introduction to Computer Architecture Summer Session I, 2005 Lecture 1 Introduction Pramod V. Argade June 27, 2005 CSE141: Introduction to Computer Architecture Instructor: Pramod V. Argade (p2argade@cs.ucsd.edu)

More information

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08 CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 20: Stack Frames 7 March 08 CS 412/413 Spring 2008 Introduction to Compilers 1 Where We Are Source code if (b == 0) a = b; Low-level IR code

More information

SMIPS Processor Specification

SMIPS Processor Specification SMIPS Processor Specification 6.884 Spring 25 - Version: 25215 1 Introduction SMIPS is the version of the MIPS instruction set architecture (ISA) we ll be using for the processors we implement in 6.884.

More information

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

An Introduction to Assembly Programming with the ARM 32-bit Processor Family An Introduction to Assembly Programming with the ARM 32-bit Processor Family G. Agosta Politecnico di Milano December 3, 2011 Contents 1 Introduction 1 1.1 Prerequisites............................. 2

More information

Intel 8086 architecture

Intel 8086 architecture Intel 8086 architecture Today we ll take a look at Intel s 8086, which is one of the oldest and yet most prevalent processor architectures around. We ll make many comparisons between the MIPS and 8086

More information

Instruction Set Architecture

Instruction Set Architecture Instruction Set Architecture Arquitectura de Computadoras Arturo Díaz D PérezP Centro de Investigación n y de Estudios Avanzados del IPN adiaz@cinvestav.mx Arquitectura de Computadoras ISA- 1 Instruction

More information

Instruction Set Design

Instruction Set Design Instruction Set Design Instruction Set Architecture: to what purpose? ISA provides the level of abstraction between the software and the hardware One of the most important abstraction in CS It s narrow,

More information

Chapter 7D The Java Virtual Machine

Chapter 7D The Java Virtual Machine This sub chapter discusses another architecture, that of the JVM (Java Virtual Machine). In general, a VM (Virtual Machine) is a hypothetical machine (implemented in either hardware or software) that directly

More information

HC12 Assembly Language Programming

HC12 Assembly Language Programming HC12 Assembly Language Programming Programming Model Addressing Modes Assembler Directives HC12 Instructions Flow Charts 1 Assembler Directives In order to write an assembly language program it is necessary

More information

PROBLEMS (Cap. 4 - Istruzioni macchina)

PROBLEMS (Cap. 4 - Istruzioni macchina) 98 CHAPTER 2 MACHINE INSTRUCTIONS AND PROGRAMS PROBLEMS (Cap. 4 - Istruzioni macchina) 2.1 Represent the decimal values 5, 2, 14, 10, 26, 19, 51, and 43, as signed, 7-bit numbers in the following binary

More information

Figure 1: Graphical example of a mergesort 1.

Figure 1: Graphical example of a mergesort 1. CSE 30321 Computer Architecture I Fall 2011 Lab 02: Procedure Calls in MIPS Assembly Programming and Performance Total Points: 100 points due to its complexity, this lab will weight more heavily in your

More information

2) Write in detail the issues in the design of code generator.

2) Write in detail the issues in the design of code generator. COMPUTER SCIENCE AND ENGINEERING VI SEM CSE Principles of Compiler Design Unit-IV Question and answers UNIT IV CODE GENERATION 9 Issues in the design of code generator The target machine Runtime Storage

More information

Introducción. Diseño de sistemas digitales.1

Introducción. Diseño de sistemas digitales.1 Introducción Adapted from: Mary Jane Irwin ( www.cse.psu.edu/~mji ) www.cse.psu.edu/~cg431 [Original from Computer Organization and Design, Patterson & Hennessy, 2005, UCB] Diseño de sistemas digitales.1

More information

Chapter 2 Topics. 2.1 Classification of Computers & Instructions 2.2 Classes of Instruction Sets 2.3 Informal Description of Simple RISC Computer, SRC

Chapter 2 Topics. 2.1 Classification of Computers & Instructions 2.2 Classes of Instruction Sets 2.3 Informal Description of Simple RISC Computer, SRC Chapter 2 Topics 2.1 Classification of Computers & Instructions 2.2 Classes of Instruction Sets 2.3 Informal Description of Simple RISC Computer, SRC See Appendix C for Assembly language information. 2.4

More information

Machine Programming II: Instruc8ons

Machine Programming II: Instruc8ons Machine Programming II: Instrucons Move instrucons, registers, and operands Complete addressing mode, address computaon (leal) Arithmec operaons (including some x6 6 instrucons) Condion codes Control,

More information

Machine-Code Generation for Functions

Machine-Code Generation for Functions Machine-Code Generation for Functions Cosmin Oancea cosmin.oancea@diku.dk University of Copenhagen December 2012 Structure of a Compiler Programme text Lexical analysis Binary machine code Symbol sequence

More information

What to do when I have a load/store instruction?

What to do when I have a load/store instruction? 76 What to do when I have a load/store instruction? Is there a label involved or a virtual address to compute? 1 A label (such as ldiq $T1, a; ldq $T0, ($T1);): a Find the address the label is pointing

More information

X86-64 Architecture Guide

X86-64 Architecture Guide X86-64 Architecture Guide For the code-generation project, we shall expose you to a simplified version of the x86-64 platform. Example Consider the following Decaf program: class Program { int foo(int

More information

M A S S A C H U S E T T S I N S T I T U T E O F T E C H N O L O G Y DEPARTMENT OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCE

M A S S A C H U S E T T S I N S T I T U T E O F T E C H N O L O G Y DEPARTMENT OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCE M A S S A C H U S E T T S I N S T I T U T E O F T E C H N O L O G Y DEPARTMENT OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCE 1. Introduction 6.004 Computation Structures β Documentation This handout is

More information

Instruction Set Architecture (ISA)

Instruction Set Architecture (ISA) Instruction Set Architecture (ISA) * Instruction set architecture of a machine fills the semantic gap between the user and the machine. * ISA serves as the starting point for the design of a new machine

More information

Pipeline Hazards. Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. Based on the material prepared by Arvind and Krste Asanovic

Pipeline Hazards. Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. Based on the material prepared by Arvind and Krste Asanovic 1 Pipeline Hazards Computer Science and Artificial Intelligence Laboratory M.I.T. Based on the material prepared by and Krste Asanovic 6.823 L6-2 Technology Assumptions A small amount of very fast memory

More information

The Operating System and the Kernel

The Operating System and the Kernel The Kernel and System Calls 1 The Operating System and the Kernel We will use the following terminology: kernel: The operating system kernel is the part of the operating system that responds to system

More information

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine 7 Objectives After completing this lab you will: know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine Introduction Branches and jumps provide ways to change

More information

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority) Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the

More information

Compilers I - Chapter 4: Generating Better Code

Compilers I - Chapter 4: Generating Better Code Compilers I - Chapter 4: Generating Better Code Lecturers: Paul Kelly (phjk@doc.ic.ac.uk) Office: room 304, William Penney Building Naranker Dulay (nd@doc.ic.ac.uk) Materials: Office: room 562 Textbook

More information

EECS 427 RISC PROCESSOR

EECS 427 RISC PROCESSOR RISC PROCESSOR ISA FOR EECS 427 PROCESSOR ImmHi/ ImmLo/ OP Code Rdest OP Code Ext Rsrc Mnemonic Operands 15-12 11-8 7-4 3-0 Notes (* is Baseline) ADD Rsrc, Rdest 0000 Rdest 0101 Rsrc * ADDI Imm, Rdest

More information

Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com

Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com CSCI-UA.0201-003 Computer Systems Organization Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com Some slides adapted (and slightly modified)

More information

A SystemC Transaction Level Model for the MIPS R3000 Processor

A SystemC Transaction Level Model for the MIPS R3000 Processor SETIT 2007 4 th International Conference: Sciences of Electronic, Technologies of Information and Telecommunications March 25-29, 2007 TUNISIA A SystemC Transaction Level Model for the MIPS R3000 Processor

More information

THUMB Instruction Set

THUMB Instruction Set 5 THUMB Instruction Set This chapter describes the THUMB instruction set. Format Summary 5-2 Opcode Summary 5-3 5. Format : move shifted register 5-5 5.2 Format 2: add/subtract 5-7 5.3 Format 3: move/compare/add/subtract

More information

Computer Organization and Components

Computer Organization and Components Computer Organization and Components IS5, fall 25 Lecture : Pipelined Processors ssociate Professor, KTH Royal Institute of Technology ssistant Research ngineer, University of California, Berkeley Slides

More information

Z80 Instruction Set. Z80 Assembly Language

Z80 Instruction Set. Z80 Assembly Language 75 Z80 Assembly Language The assembly language allows the user to write a program without concern for memory addresses or machine instruction formats. It uses symbolic addresses to identify memory locations

More information

Instruction Set Architecture

Instruction Set Architecture CS:APP Chapter 4 Computer Architecture Instruction Set Architecture Randal E. Bryant adapted by Jason Fritts http://csapp.cs.cmu.edu CS:APP2e Hardware Architecture - using Y86 ISA For learning aspects

More information

Systems I: Computer Organization and Architecture

Systems I: Computer Organization and Architecture Systems I: Computer Organization and Architecture Lecture : Microprogrammed Control Microprogramming The control unit is responsible for initiating the sequence of microoperations that comprise instructions.

More information

Solutions. Solution 4.1. 4.1.1 The values of the signals are as follows:

Solutions. Solution 4.1. 4.1.1 The values of the signals are as follows: 4 Solutions Solution 4.1 4.1.1 The values of the signals are as follows: RegWrite MemRead ALUMux MemWrite ALUOp RegMux Branch a. 1 0 0 (Reg) 0 Add 1 (ALU) 0 b. 1 1 1 (Imm) 0 Add 1 (Mem) 0 ALUMux is the

More information

Chapter 4 Lecture 5 The Microarchitecture Level Integer JAVA Virtual Machine

Chapter 4 Lecture 5 The Microarchitecture Level Integer JAVA Virtual Machine Chapter 4 Lecture 5 The Microarchitecture Level Integer JAVA Virtual Machine This is a limited version of a hardware implementation to execute the JAVA programming language. 1 of 23 Structured Computer

More information

1 The Java Virtual Machine

1 The Java Virtual Machine 1 The Java Virtual Machine About the Spec Format This document describes the Java virtual machine and the instruction set. In this introduction, each component of the machine is briefly described. This

More information

Instruction Set Reference

Instruction Set Reference 2015.04.02 Set Reference NII51017 Subscribe This section introduces the Nios II instruction word format and provides a detailed reference of the Nios II instruction set. Word Formats There are three types

More information

Computer Organization and Components

Computer Organization and Components Computer Organization and Components IS1500, fall 2015 Lecture 5: I/O Systems, part I Associate Professor, KTH Royal Institute of Technology Assistant Research Engineer, University of California, Berkeley

More information

Assembly Language: Function Calls" Jennifer Rexford!

Assembly Language: Function Calls Jennifer Rexford! Assembly Language: Function Calls" Jennifer Rexford! 1 Goals of this Lecture" Function call problems:! Calling and returning! Passing parameters! Storing local variables! Handling registers without interference!

More information

Computer organization

Computer organization Computer organization Computer design an application of digital logic design procedures Computer = processing unit + memory system Processing unit = control + datapath Control = finite state machine inputs

More information

Keil C51 Cross Compiler

Keil C51 Cross Compiler Keil C51 Cross Compiler ANSI C Compiler Generates fast compact code for the 8051 and it s derivatives Advantages of C over Assembler Do not need to know the microcontroller instruction set Register allocation

More information

MICROPROCESSOR AND MICROCOMPUTER BASICS

MICROPROCESSOR AND MICROCOMPUTER BASICS Introduction MICROPROCESSOR AND MICROCOMPUTER BASICS At present there are many types and sizes of computers available. These computers are designed and constructed based on digital and Integrated Circuit

More information

Instruction Set Architecture (ISA) Design. Classification Categories

Instruction Set Architecture (ISA) Design. Classification Categories Instruction Set Architecture (ISA) Design Overview» Classify Instruction set architectures» Look at how applications use ISAs» Examine a modern RISC ISA (DLX)» Measurement of ISA usage in real computers

More information

8085 INSTRUCTION SET

8085 INSTRUCTION SET DATA TRANSFER INSTRUCTIONS Opcode Operand Description 8085 INSTRUCTION SET INSTRUCTION DETAILS Copy from source to destination OV Rd, Rs This instruction copies the contents of the source, Rs register

More information

COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms.

COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms. COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms 1 Activation Records activation declaration location Recall that an activation

More information

Lecture 8: Binary Multiplication & Division

Lecture 8: Binary Multiplication & Division Lecture 8: Binary Multiplication & Division Today s topics: Addition/Subtraction Multiplication Division Reminder: get started early on assignment 3 1 2 s Complement Signed Numbers two = 0 ten 0001 two

More information

Stacks. Linear data structures

Stacks. Linear data structures Stacks Linear data structures Collection of components that can be arranged as a straight line Data structure grows or shrinks as we add or remove objects ADTs provide an abstract layer for various operations

More information

Central Processing Unit Simulation Version v2.5 (July 2005) Charles André University Nice-Sophia Antipolis

Central Processing Unit Simulation Version v2.5 (July 2005) Charles André University Nice-Sophia Antipolis Central Processing Unit Simulation Version v2.5 (July 2005) Charles André University Nice-Sophia Antipolis 1 1 Table of Contents 1 Table of Contents... 3 2 Overview... 5 3 Installation... 7 4 The CPU

More information

The stack and the stack pointer

The stack and the stack pointer The stack and the stack pointer If you google the word stack, one of the definitions you will get is: A reserved area of memory used to keep track of a program's internal operations, including functions,

More information

1 Classical Universal Computer 3

1 Classical Universal Computer 3 Chapter 6: Machine Language and Assembler Christian Jacob 1 Classical Universal Computer 3 1.1 Von Neumann Architecture 3 1.2 CPU and RAM 5 1.3 Arithmetic Logical Unit (ALU) 6 1.4 Arithmetic Logical Unit

More information

How To Write An Array In A Microsoft Zil

How To Write An Array In A Microsoft Zil Array Declaration and Storage Allocation The first step is to reserve sufficient space for the array: 1.data list:.space 1000 # reserves a block of 1000 bytes This yields a contiguous block of bytes of

More information

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection

More information

Pseudo code Tutorial and Exercises Teacher s Version

Pseudo code Tutorial and Exercises Teacher s Version Pseudo code Tutorial and Exercises Teacher s Version Pseudo-code is an informal way to express the design of a computer program or an algorithm in 1.45. The aim is to get the idea quickly and also easy

More information

Introduction to the Altera Nios II Soft Processor. 1 Introduction. For Quartus II 11.1

Introduction to the Altera Nios II Soft Processor. 1 Introduction. For Quartus II 11.1 Introduction to the Altera Nios II Soft Processor For Quartus II 11.1 1 Introduction This tutorial presents an introduction to Altera s Nios II processor, which is a soft processor that can be instantiated

More information

Lab Work 2. MIPS assembly and introduction to PCSpim

Lab Work 2. MIPS assembly and introduction to PCSpim Lab Work 2. MIPS assembly and introduction to PCSpim The goal of this work is for the student to become familiar with the data types and the programming in assembly (MIPS32). To realize this lab work you

More information

Interpreters and virtual machines. Interpreters. Interpreters. Why interpreters? Tree-based interpreters. Text-based interpreters

Interpreters and virtual machines. Interpreters. Interpreters. Why interpreters? Tree-based interpreters. Text-based interpreters Interpreters and virtual machines Michel Schinz 2007 03 23 Interpreters Interpreters Why interpreters? An interpreter is a program that executes another program, represented as some kind of data-structure.

More information

Design of Digital Circuits (SS16)

Design of Digital Circuits (SS16) Design of Digital Circuits (SS16) 252-0014-00L (6 ECTS), BSc in CS, ETH Zurich Lecturers: Srdjan Capkun, D-INFK, ETH Zurich Frank K. Gürkaynak, D-ITET, ETH Zurich Labs: Der-Yeuan Yu dyu@inf.ethz.ch Website:

More information

PART B QUESTIONS AND ANSWERS UNIT I

PART B QUESTIONS AND ANSWERS UNIT I PART B QUESTIONS AND ANSWERS UNIT I 1. Explain the architecture of 8085 microprocessor? Logic pin out of 8085 microprocessor Address bus: unidirectional bus, used as high order bus Data bus: bi-directional

More information

EC 362 Problem Set #2

EC 362 Problem Set #2 EC 362 Problem Set #2 1) Using Single Precision IEEE 754, what is FF28 0000? 2) Suppose the fraction enhanced of a processor is 40% and the speedup of the enhancement was tenfold. What is the overall speedup?

More information

An Introduction to the ARM 7 Architecture

An Introduction to the ARM 7 Architecture An Introduction to the ARM 7 Architecture Trevor Martin CEng, MIEE Technical Director This article gives an overview of the ARM 7 architecture and a description of its major features for a developer new

More information

Introduction to MIPS Programming with Mars

Introduction to MIPS Programming with Mars Introduction to MIPS Programming with Mars This week s lab will parallel last week s lab. During the lab period, we want you to follow the instructions in this handout that lead you through the process

More information

l C-Programming l A real computer language l Data Representation l Everything goes down to bits and bytes l Machine representation Language

l C-Programming l A real computer language l Data Representation l Everything goes down to bits and bytes l Machine representation Language 198:211 Computer Architecture Topics: Processor Design Where are we now? C-Programming A real computer language Data Representation Everything goes down to bits and bytes Machine representation Language

More information

ASSEMBLY PROGRAMMING ON A VIRTUAL COMPUTER

ASSEMBLY PROGRAMMING ON A VIRTUAL COMPUTER ASSEMBLY PROGRAMMING ON A VIRTUAL COMPUTER Pierre A. von Kaenel Mathematics and Computer Science Department Skidmore College Saratoga Springs, NY 12866 (518) 580-5292 pvonk@skidmore.edu ABSTRACT This paper

More information

Central Processing Unit (CPU)

Central Processing Unit (CPU) Central Processing Unit (CPU) CPU is the heart and brain It interprets and executes machine level instructions Controls data transfer from/to Main Memory (MM) and CPU Detects any errors In the following

More information

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1 Divide: Paper & Pencil Computer Architecture ALU Design : Division and Floating Point 1001 Quotient Divisor 1000 1001010 Dividend 1000 10 101 1010 1000 10 (or Modulo result) See how big a number can be

More information

Sources: On the Web: Slides will be available on:

Sources: On the Web: Slides will be available on: C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

More information

ELEG3924 Microprocessor Ch.7 Programming In C

ELEG3924 Microprocessor Ch.7 Programming In C Department of Electrical Engineering University of Arkansas ELEG3924 Microprocessor Ch.7 Programming In C Dr. Jingxian Wu wuj@uark.edu OUTLINE 2 Data types and time delay I/O programming and Logic operations

More information

Syscall 5. Erik Jonsson School of Engineering and Computer Science. The University of Texas at Dallas

Syscall 5. Erik Jonsson School of Engineering and Computer Science. The University of Texas at Dallas Syscall 5 System call 5 allows input of numerical data from the keyboard while a program is running. Syscall 5 is a bit unusual, in that it requires the use of register $v0 twice. In syscall 5 (as for

More information

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2 Lecture Handout Computer Architecture Lecture No. 2 Reading Material Vincent P. Heuring&Harry F. Jordan Chapter 2,Chapter3 Computer Systems Design and Architecture 2.1, 2.2, 3.2 Summary 1) A taxonomy of

More information

Administrative Issues

Administrative Issues CSC 3210 Computer Organization and Programming Introduction and Overview Dr. Anu Bourgeois (modified by Yuan Long) Administrative Issues Required Prerequisites CSc 2010 Intro to CSc CSc 2310 Java Programming

More information

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void 1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of

More information

Comp 255Q - 1M: Computer Organization Lab #3 - Machine Language Programs for the PDP-8

Comp 255Q - 1M: Computer Organization Lab #3 - Machine Language Programs for the PDP-8 Comp 255Q - 1M: Computer Organization Lab #3 - Machine Language Programs for the PDP-8 January 22, 2013 Name: Grade /10 Introduction: In this lab you will write, test, and execute a number of simple PDP-8

More information

Design of Pipelined MIPS Processor. Sept. 24 & 26, 1997

Design of Pipelined MIPS Processor. Sept. 24 & 26, 1997 Design of Pipelined MIPS Processor Sept. 24 & 26, 1997 Topics Instruction processing Principles of pipelining Inserting pipe registers Data Hazards Control Hazards Exceptions MIPS architecture subset R-type

More information

x64 Cheat Sheet Fall 2015

x64 Cheat Sheet Fall 2015 CS 33 Intro Computer Systems Doeppner x64 Cheat Sheet Fall 2015 1 x64 Registers x64 assembly code uses sixteen 64-bit registers. Additionally, the lower bytes of some of these registers may be accessed

More information

Chapter 5 Instructor's Manual

Chapter 5 Instructor's Manual The Essentials of Computer Organization and Architecture Linda Null and Julia Lobur Jones and Bartlett Publishers, 2003 Chapter 5 Instructor's Manual Chapter Objectives Chapter 5, A Closer Look at Instruction

More information

Stack Allocation. Run-Time Data Structures. Static Structures

Stack Allocation. Run-Time Data Structures. Static Structures Run-Time Data Structures Stack Allocation Static Structures For static structures, a fixed address is used throughout execution. This is the oldest and simplest memory organization. In current compilers,

More information

CPU Organization and Assembly Language

CPU Organization and Assembly Language COS 140 Foundations of Computer Science School of Computing and Information Science University of Maine October 2, 2015 Outline 1 2 3 4 5 6 7 8 Homework and announcements Reading: Chapter 12 Homework:

More information

COMPUTER ORGANIZATION ARCHITECTURES FOR EMBEDDED COMPUTING

COMPUTER ORGANIZATION ARCHITECTURES FOR EMBEDDED COMPUTING COMPUTER ORGANIZATION ARCHITECTURES FOR EMBEDDED COMPUTING 2013/2014 1 st Semester Sample Exam January 2014 Duration: 2h00 - No extra material allowed. This includes notes, scratch paper, calculator, etc.

More information

The AVR Microcontroller and C Compiler Co-Design Dr. Gaute Myklebust ATMEL Corporation ATMEL Development Center, Trondheim, Norway

The AVR Microcontroller and C Compiler Co-Design Dr. Gaute Myklebust ATMEL Corporation ATMEL Development Center, Trondheim, Norway The AVR Microcontroller and C Compiler Co-Design Dr. Gaute Myklebust ATMEL Corporation ATMEL Development Center, Trondheim, Norway Abstract High Level Languages (HLLs) are rapidly becoming the standard

More information

a storage location directly on the CPU, used for temporary storage of small amounts of data during processing.

a storage location directly on the CPU, used for temporary storage of small amounts of data during processing. CS143 Handout 18 Summer 2008 30 July, 2008 Processor Architectures Handout written by Maggie Johnson and revised by Julie Zelenski. Architecture Vocabulary Let s review a few relevant hardware definitions:

More information

2.2: Bitwise Logical Operations

2.2: Bitwise Logical Operations 2.2: Bitwise Logical Operations Topics: Introduction: logical operations in C/C++ logical operations in MIPS In 256 lecture, we looked at bitwise operations in C/C++ and MIPS. We ll look at some simple

More information

A Tiny Guide to Programming in 32-bit x86 Assembly Language

A Tiny Guide to Programming in 32-bit x86 Assembly Language CS308, Spring 1999 A Tiny Guide to Programming in 32-bit x86 Assembly Language by Adam Ferrari, ferrari@virginia.edu (with changes by Alan Batson, batson@virginia.edu and Mike Lack, mnl3j@virginia.edu)

More information