Upload
max
View
52
Download
0
Embed Size (px)
DESCRIPTION
CS334: MIPS language _Mars simulator Lab 2_1. Contents: introduction. Part1:MIPS assembly language . Questions. Assembly Language. Instructions are the primitive operations that the CPU may execute. - PowerPoint PPT Presentation
Citation preview
CS334: MIPS language _Mars simulator
Lab 2_1
Ins.Ebtesam AL-Etowi
Contents:• introduction.• Part1:MIPS assembly language.• Questions.
Ins.Ebtesam AL-Etowi
Assembly Language
Instructions are the primitive operations that the CPU may execute.Different CPUs implement different sets of instructions. The set of instructions a particular CPU implements is an Instruction Set Architecture (ISA).
Examples: Intel 80x86 (Pentium 4), IBM/Motorola PowerPC (Macintosh), MIPS, Intel IA64, ...
Ins.Ebtesam AL-Etowi
MIPS Architecture
MIPS – semiconductor company that built one of the first commercial RISC architectures
MIPS is simple, elegant.Assembly Operands are registersGroups of 32 bits called a word in MIPS
The Text segment shows you:Address -- where this instruction is stored in memoryCode -- the machine code of the instructionBasic -- [not too helpful at this point]Source -- the original instruction you typed in
Ins.Ebtesam AL-Etowi
List of Instructions
Ins.Ebtesam AL-Etowi
Part 1: MIPS
Start the program with:
.textThis says that the following are program instructions (and not, e.g.,data) .
Let's do the following:
$t1 = 3 + 5 + 9First, let's put 3 in $t1:
addi $t1, $zero, 3
Ins.Ebtesam AL-Etowi
Part 1: MIPS (cont…)
This says to take what is stored in register $zero, add 3 to it, and put the result in register $t1 .
$zero ALWAYS contains 0, so this puts 0 + 3 into register $t1
Now we want to add 5 to our running sum:
addi $t1, $t1, 5
And then we want to add 9:
addi $t1, $t1, 9
Save and Assemble the program (run it). You will see that $t1 contains 0x00000011
The 0x just means that the number following it is in hex.
Ins.Ebtesam AL-Etowi
Performing the program
Pc : Special register keeping the address of next instruction . Read the code from memory by pc .
$at : assembler temporary as handle for save value .
Ins.Ebtesam AL-Etowi
Questions
Question 1: What decimal number is 0x00000011?
Question 2: before the first instruction is executed (the program counter is the register labeled "pc")program counter = __________
Answer: 17
program counter = 0x00400000
Ins.Ebtesam AL-Etowi
Cont..)) Questions
Question 3: after the first instruction is executed:program counter = $t1 =
Question 4: after the second instruction is executed:program counter =
$t1 = ____________
program counter = 0x00400004
$t1 = 0x00000003
program counter = 0x00400008
$t1 = 0x00000008
Cont..)) Questions
Ins.Ebtesam AL-Etowi
Question 5: after the third instruction is executed:program counter = ___________ $t1 = _____________
Question 6: Complete this sentence:After each instruction, the PC is incremented so that it contains:1) A bit which is a 0 or 1.2) A byte which is 8 bits.3) A word which is 4 bytes.
program counter = 0x0040000C
$t1 = 0x00000011
Ins.Ebtesam AL-Etowi
Cont..)) Questions
Hint : In a MIPS architecture, each byte has its own address (the byte is the "addressable unit").
Question 7: How big are instructions in MIPS ? Number of bits=
Number of bytes = Number of words =
324
1
Ins.Ebtesam AL-Etowi
conclusion
This shows a good way to learn assembly language. Enter and assemble instructions; this will show you the machine code that is produced. Then, step through execution so you can see the effects of the individual instructions.
Ins.Ebtesam AL-Etowi
exercise
f = (g + h) - (i + j)
to perform the calculation:
g= 5h= -20i= 13 j= 3
Ins.Ebtesam AL-Etowi
Ins.Ebtesam AL-Etowi
H.W for absent
You are given the following two numbers in two’s complement representation.
Perform the binary addition and subtraction. Did signed overflow occur? determined whether or not overflow occurred.
0010110000101100
00101100
- 00101100