Instruction Set Architectures Part I: From C to MIPS
Practice
?
Translate the C code into assembly:
label
and
for(i = 0; i < 100; i++)
addi
{
LOOP: lw
sum+=A[i];
add
}
addi
addi
bne
1. initialization
2. load A[i] from memory to register
3. add the value of A[i] to sum
4. increase by 1
5. check if i still < 100
$t0,
$t1,
$t3,
$v0,
$s0,
$t0,
$t1,
$t0, $zero
$zero, 100
0($s0)
$v0, $t3
$s0, 4
$t0, 1
$t0, LOOP
#let i = 0
#temp = 100
#temp1 = A[i]
#sum += temp1
#addr of A[i+1]
#i = i+1
#if i < 100
Assume
int is 32 bits
$s0 = &A[0]
$v0 = sum;
$t0 = i;
36
To implement the following C code, what are the
instructions that we should put in the box?
add $t0, $zero, $zero
addi $t1, $zero, 100
for(i = 0; i < 100; i++)
A[i] = i;
LOOP:
addi $t0, $t0, 1
beq $t0, $t1, LOOP
A:
lw
$t0, 0($s2)
addi $s2, $s2, 4
C:
sw
$t0, 0($s2)
addi $s2, $s2, 4
B:
sw
$t1, 0($s2)
addi $s2, $s2, 4
D:
sw
$t1, 0($s2)
addi $s2, $s2, 1
37
MIPS Mystery 1: Delayed Loads
Example
? The value retrieved
by a load is not
available to the
next instruction.
ori
sw
lw
or
or
$t0,
$t0,
$t1,
$t2,
$t3,
$zero, 4
0($sp)
0($sp)
$t1, $zero
$t1, $zero
$t2 == 0
$t3 == 4
file: delayed_load.s
Why? We¡¯ll talk about it in a few weeks.
38
MIPS Mystery 2: Delayed Branches
? The instruction
?
after the branch
executes even if
the branch is taken.
All jumps and
branches are
delayed -- the next
instruction always
executes
Example
ori $t0, $zero, 4
beq $t0, $t0, foo
ori $t0, $zero, 5
foo:
$t0 == 5
file: delayed_branch.s
Why? We¡¯ll talk about it in a few weeks.
39
Pseudo Instructions
?
?
?
?
Assembly language programming is repetitive
Some code is not very readable
The assembler provides some simple
shorthand for common operations
Register $at is reserved for implementing them.
Assembly
Shorthand
Description
or $s1, $zero, $s2
mov $s1, $s2
move
beq $zero, $zero,
b
unconditional branch
Homework?
li $s2,
load 32 bit constant
Homework?
nop
do nothing
Homework?
div d, s1, s2
dst = src1/src2
Homework?
mulou d, s1, s2
dst = low32bits(src1*src2)
53
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- digital to analog converter lab 3 final report
- setting the c carry v overflo w n negative and z
- lecture 27 c and assembly
- ada 95 a guide for c and c programmers
- using pwm to generate an analog output
- analog to digital converters
- 1 design a gray code to bcd converter by the following
- instruction set architectures part i from c to mips
- translating c code to mips github pages
- cnccookbook s g code course
Related searches
- adjectives starting with c to describe people
- medicare part a b c d explained
- how to switch from survival to creative
- how to get from grams to tons
- how to go from ml to moles
- how to convert from moles to grams
- how to convert from pdf to txt
- how to convert from miles to kilometers
- how to convert from mph to mpm
- how to convert from miles to meters
- how to scan from printer to computer
- move from c drive to d drive