MIPS Assembly and Computer Organization: A Comprehensive Guide, Exams of Computer Science

An in-depth exploration of mips assembly language, computer organization, and the conversion between binary, decimal, and hexadecimal representations. Topics include understanding the five classic components of a computer, mips assembly instructions, register usage, arithmetic operations, branches, and procedures. Additionally, it covers the representation and manipulation of negative integers, binary integer multiplication and division, and floating-point numbers using ieee 754 format.

Typology: Exams

2019/2020

Uploaded on 10/21/2021

bdome
bdome 🇺🇸

1 document

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter 1
- What are the five classic components of computer?
1. Input:keyboard, mouse2. Output:Screen3. Memory:primary–RAM (DRAM, SRAM), cache memory --Secondary – (magnetic) disks4. Datapath: the component of the processor that performs
arithmetic operationsarithmeticoperations5. Control: the component of the processor that commands the datapath, memory, I/O devices
Mynote: msg1: . asciiz “Hello\n” ---- num1: .word 73 ---- num2: .word 0xAB6C ----- array1: .word 1,2,3,4,5
Chapter 2
-How to convert among binary, decimal, and hex representations.
- Registers , $zero (0), $v0-$v1 (green), $a0-$a3 (), $t0-$t7 (“Temp” math), $s0-$s7 (“Saved” for variables), $t8-$t9 , $sp (Stack-Pointer), $ra (return-addr) –
MIPS assembly instructions, add, sub, addi (add-immediate “$t0, $t1, 5” reg always first), lw (lo adword “lw $s1, offset($t1)”to get val at $t1 + offset), sw (store-word “sw $t1, 0($s3)” to store
in MM the val at $s3 + offset), move (“$t0, $t1” #t0=t1), and (binary compare t0,t1,t2 ), or (t0,t1,t2), nor (not OR, so do or operation then negate t0,t1,t2), andi(t0, t1, 5), ori , sll (shift left logical//
$t0=$s2*2^i), srl (shift right logical), bne (branch on not equal[I-type]// t0,t1,label – if t0 != t1, go to label), beq (branch on equal[I-type]// if t0 == t1 go to…), bgt , bge , blt , ble , sgt , sge , sle ,
slt (set on less than//$t0, $s0, $s1 == if s0 < s1// [ if(a>=b) == !(a<b) ]), slti (set o n less than immediate//$t0, $s0, 87 == if s0 < 87), J (jump), jal (jump and link// call a function), jr (jump
register), mul , div , mflo [(multi = lower32bits of result) // (div = quotient)], mfhi [(multi = higher 32) // (div = remainder)], la(load array// la $a0, array a0=array[ ])
-Know how to convert a MIPS assembly instruction to the corresponding Machine code using
binary, decimal, or hex, for add, sub, addi, lw, sw, and, or, nor, andi, ori, sll, srl, beq, bne, slt, slti, j, and jr.
-Know R-type [ex: add, sub -- don’t require immediate nor offset(6,5,5,5,5,6)], I-type [ex: lw, sw, addi – l w $t0, 32($s2) where t0=rt, s2=rs, 32=offset (6,5,5,16)], J-type [(6,26)].
And also from a given machine code (using binary decimal, or hex), convert to the corresponding MIPS assembly instruction.
1.) (jr jump register R-Type) plug in vals from green sheet; 2.) (bne $t0, $t1, Label I-type) const = [BA – PC - 4]/4 (div will take away last 2 bits); 3.) (j jump J-Type) JAddr=
append4bit(const * 4)—append is (PC-4)
-How to convert “if, if-else, if-else if, else, …” statements in C into MIPS assembly code. -How to convert loops in C into MIPS assembly code .
-How to create procedures in MIPS assembly code, how to call them, using the stack pointer.
-How to operate arithmetic operations in MIPS assembly code, how to use arrays of integers in MIPS assembly code.
-branch with PC-relative addressing, jump with Pseudo-direct addressing. -Spilling Registers technique$v0-$v1(parameters), $a0-$a3 (return val) [**see $sp code pic]
*if a function is calling another function- $ra val needs to be stored(sw) in MM before jal, and we get its value back(lw) from MM after jal and before jr $ra
*if a functionA is modifying the vals for regs. used by the function that call the functionA, THEN these reg vals need to be stored(sw) at the beginning of the functionA (before val are changed) --
and load them back(lw) at the end of functionA (before jr $ra)
Chapter 3
-How to represent negative integers using 2’s complement representation. -Convert a number in 2’s complement representation into a signed decimal number. -How to
detect overflow for addition and subtraction
Sign extension (using left most bit to fill missing bits needed 4b8b = 1000 1111 1000)
1.) [pos + pos neg] 2.) [neg + neg pos] 3.) [pos – neg neg] 4.) [neg – pos pos]
pf2

Partial preview of the text

Download MIPS Assembly and Computer Organization: A Comprehensive Guide and more Exams Computer Science in PDF only on Docsity!

Chapter 1

- What are the five classic components of computer?

  1. Input :keyboard, mouse2. Output :Screen3. Memory :primary–RAM (DRAM, SRAM), cache memory --Secondary – (magnetic) disks4. Datapath : the component of the processor that performs arithmetic operationsarithmeticoperations5. Control : the component of the processor that commands the datapath, memory, I/O devices Mynote: msg1:. asciiz “Hello\n” ---- num1: .word 73 ---- num2: .word 0xAB6C ----- array1: .word 1,2,3,4, Chapter 2 **_-How to convert among binary, decimal, and hex representations.
  • Registers_** , $zero(0), $v0-$v1(green), $a0-$a3(), $t0-$t7(“Temp” math), $s0-$s7(“Saved” for variables), $t8-$t9, $sp(Stack-Pointer), $ra(return-addr) – MIPS assembly instructions , add, sub, addi (add-immediate “$t0, $t1, 5” reg always first), lw(loadword “lw $s1, offset($t1)”to get val at $t1 + offset), sw(store-word “sw $t1, 0($s3)” to store in MM the val at $s3 + offset), move(“$t0, $t1” #t0=t1), and(binary compare t0,t1,t2 ), or(t0,t1,t2), nor(not OR, so do or operation then negate t0,t1,t2), andi(t0, t1, 5), ori, sll(shift left logical// $t0=$s22^i), srl(shift right logical), bne(branch on not equal[I-type]// t0,t1,label – if t0 != t1, go to label), beq(branch on equal[I-type]// if t0 == t1 go to…), bgt, bge, blt, ble, sgt, sge, sle, slt(set on less than//$t0, $s0, $s1 == if s0 < s1// [ if(a>=b) == !(a<b) ]), slti(set on less than immediate//$t0, $s0, 87 == if s0 < 87), J (jump), jal(jump and link// call a function), jr(jump register), mul, div, mflo[(multi = lower32bits of result) // (div = quotient)], mfhi[(multi = higher 32) // (div = remainder)], la(load array// la $a0, array  a0=array[ ]) -Know how to convert a MIPS assembly instruction to the corresponding Machine code using binary, decimal, or hex, for add, sub, addi, lw, sw, and, or, nor, andi, ori, sll, srl, beq, bne, slt, slti, j, and jr. -Know R-type[ex: add, sub -- don’t require immediate nor offset(6,5,5,5,5,6)], I-type[ex: lw, sw, addi – lw $t0, 32($s2) where t0=rt, s2=rs, 32=offset (6,5,5,16)], J-type[(6,26)]. And also from a given machine code (using binary decimal, or hex), convert to the corresponding MIPS assembly instruction. 1.) (jr  jump register R-Type) plug in vals from green sheet; 2.) (bne $t0, $t1, Label I-type) const = [BA – PC - 4]/4 (div will take away last 2 bits); 3.) (j  jump J-Type) JAddr= append4bit(const * 4)—append is (PC-4) -How to convert “if, if-else, if-else if, else, …” statements in C into MIPS assembly code. -How to convert loops in C into MIPS assembly code. -How to create procedures in MIPS assembly code, how to call them, using the stack pointer. -How to operate arithmetic operations in MIPS assembly code, how to use arrays of integers in MIPS assembly code. -branch with PC-relative addressing, jump with Pseudo-direct addressing. -Spilling Registers technique $v0-$v1(parameters), $a0-$a3(return val) [*see $sp code pic] *if a function is calling another function- $ra val needs to be stored(sw) in MM before jal, and we get its value back(lw) from MM after jal and before jr $ra *if a functionA is modifying the vals for regs. used by the function that call the functionA, THEN these reg vals need to be stored(sw) at the beginning of the functionA (before val are changed) -- and load them back(lw) at the end of functionA (before jr $ra) Chapter 3 -How to represent negative integers using 2’s complement representation. -Convert a number in 2’s complement representation into a signed decimal number. -How to detect overflow for addition and subtraction Sign extension (using left most bit to fill missing bits needed 4b8b = 1000  1111 1000) 1.) [pos + pos  neg] 2.) [neg + neg  pos] 3.) [pos – neg  neg] 4.) [neg – pos  pos]

-Binary integer Multiplication/Division -Binary fraction, floating point numbers [11101. 11  (-1)x 1.1101112^4] OR [-0.00101  (-1) x 1.01 x 2^-3] // 35.25== (35 = 2^5+2^1+2^0) , (25= {0.252= 0.5} , {0.5*2=1})== 100011. 01 -IEEE 754 floating point single precision representation, double precision representation -Biased exponent [SP 1bit, 8, 23 Bias:127] (0.5+(-0.4375)== 1. Convert to binary format 2^, 2.lesser expo adjust to meet, 3. Add both, format the new sum, 4. Round and truncate or round and conv to dec) [DP 1, 11, 20 Bias: 1022] -Binary floating-point addition/multiplication -Guard digits, rounding