7.1. Machine Instructions

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 9

1/3/2019 7.1. Machine instructions
https://learn.zybooks.com/zybook/FIUCDA3103CickovskiFall2018/chapter/7/section/1 1/9
7.1 Machine instructions
Load, store, and add as 0s and 1s
A processor processes instructions in the form of 0's and 1's, each known as a machine instruction. In MIPS, each machine
32 bits. Some bits, called the opcode ("operation code"), encode a machine instruction's operations like load word, store wo
machine instruction bits, each known as an operand, indicate what register, address, or literal values are involved in an instr
PARTICIPATION
ACTIVITY 7.1.1: Representing MIPS assembly instructions as machine instructions.
PARTICIPATION
ACTIVITY 7.1.2: Machine instructions.
01000
6 bits 16 bits5 bits5 bits
100011
$t0: 01000
$t1: 01001
$t2: 01010
$t3: 01011
$t4: 01100
$t5: 01101
$t6: 01110
$zero: 00000
01110 0000000000000000
lw $t0, 0($t6)
01000101011 01110 0000000000000000
sw $t0, 0($t6)
01000000000 01010
add $t0, $t1, $t2
6 bits 5 bits5 bits 5 bits 5 bits 6 bits
01001 10000000000
01000001000 01001 0000000000001111
addi $t0, $t1,15
Start 2x speed
1/3/2019 7.1. Machine instructions
https://learn.zybooks.com/zybook/FIUCDA3103CickovskiFall2018/chapter/7/section/1 2/9
Refer to the above assembly and machine instructions.
1) lw's opcode is _____ .
2) Registers like $t0 or $t6 are encoded
using how many bits?
3) Register $t0 is encoded as _____ .
4) In the lw machine instruction, the
second eld represents the _____ .
5) In the addi machine instruction, the
immediate is represented by how many
bits?
000000
100011
101001
5
6
00000
01000
01110
destination register
immediate
base address
5
6
16
1/3/2019 7.1. Machine instructions
https://learn.zybooks.com/zybook/FIUCDA3103CickovskiFall2018/chapter/7/section/1 3/9
6) How many bits are used to denote that
an instruction should perform an add?
7) In the add machine instruction, the
second eld is the destination register.
PARTICIPATION
ACTIVITY 7.1.3: Translating an lw assembly instruction to a MIPS machine instruction.
Finish translating this assembly instruction to a machine instruction:
lw $t6, 0($t2)
__a___ __b__ __c__ 0000000000000000
1) a
2) b
3) c
6
12
True
False
Check Show answer
Check Show answer
Check Show answer
1/3/2019 7.1. Machine instructions
https://learn.zybooks.com/zybook/FIUCDA3103CickovskiFall2018/chapter/7/section/1 4/9
PARTICIPATION
ACTIVITY 7.1.4: Translating an add assembly instruction to a MIPS machine instruction.
Finish translating this assembly instruction to a machine instruction:
add $t6, $t5, $t4
__a___ __b__ __c__ __d__ 00000 __e___
1) a
2) b
3) c
4) d
5) e
Check Show answer
Check Show answer
Check Show answer
Check Show answer
1/3/2019 7.1. Machine instructions
https://learn.zybooks.com/zybook/FIUCDA3103CickovskiFall2018/chapter/7/section/1 5/9
MIPSzy machine instructions
The table below shows MIPSzy's register encodings. The subsequent table shows all of MIPSzy's machine instructions, wit
blue, registers in orange, green, and red, immediate values in purple, and unused bits in grey.
Table 7.1.1: MIPSzy register encodings.
Name $zero $t0 $t1 $t2 $t3 $t4 $t5 $t6
Encoding 00000 01000 01001 01010 01011 01100 01101 01110
Table 7.1.2: MIPSzy machine instructions.
Assembly Machine
lw $t0, 0($t1)100011 01001 010000000000000000000
sw $t0, 0($t1)101011 01001 010000000000000000000
addi $t0, $t1, 15 001000 01001 010000000000000001111
add $t0, $t1, $t2 000000 01001 01010 01000 00000 100000
sub $t0, $t1, $t2 000000 01001 01010 01000 00000 100010
mult $t1, $t2 000100 01001 01010 00000 00000 011000
Check Show answer
1/3/2019 7.1. Machine instructions
https://learn.zybooks.com/zybook/FIUCDA3103CickovskiFall2018/chapter/7/section/1 6/9
PARTICIPATION
ACTIVITY 7.1.5: MIPSzy machine instructions.
1) Different MIPSzy instructions have
different numbers of bits.
2) addi uses _____ bits for the immediate
value.
mflo $t0 000000 00000 00000 01000 00000 010010
beq $t1, $t2, BLabel 000100 01001 010100000000000000010
bne $t1, $t2, BLabel 000101 01001 010100000000000000010
slt $t0, $t1, $t2 000000 01001 01010 01000 00000 101010
j JLabel 00001000000000000000000000000101
jal JLabel 00001100000000000000100000000101
jr $t1 000000 01001 00000 00000 00000 001000
Assume BLabel becomes an immediate of 2, and JLabel 5. Creating immediates for branches/jumps is in another section.
$t0, $t1, and $t2 are used for registers. Other registers could be used.
addi's immediate value is shown as 15. That value is arbitrary.
True
False
5
16
1/3/2019 7.1. Machine instructions
https://learn.zybooks.com/zybook/FIUCDA3103CickovskiFall2018/chapter/7/section/1 7/9
3) For a sub instruction, the rst 6 bits are
000000, and the last 6 bits are _____ .
4) add and sub make use of all 32 bits.
5) For an slt instruction, the rst 6 bits are
000000, and the last 6 bits are _____ .
6) For a j instruction, the immediate is
_____ bits.
PARTICIPATION
ACTIVITY 7.1.6: Translating an addi instruction to a MIPS machine instruction.
Finish translating this assembly instruction to a machine instruction:
addi $t3, $t4, 7
__a___ __b__ __c__ 0000000000___d___
1) a
100000
100010
True
False
101010
000000
26
32
Check Show answer
1/3/2019 7.1. Machine instructions
https://learn.zybooks.com/zybook/FIUCDA3103CickovskiFall2018/chapter/7/section/1 8/9
2) b
3) c
4) d (just the last 6 bits of the immediate
eld).
Executable les
Assembly instructions can be translated to machine instructions. An executable le contains the 0's and 1's of a program's
instructions and can be loaded into an instruction memory and then executed (run). The 0's and 1's are placed into a proces
memory, and the processor then executes each machine instruction.
PARTICIPATION
ACTIVITY
7.1.7: Assembly instructions can be translated to machine instructions (0's and
1's) representing an executable le.
Check Show answer
Check Show answer
Check Show answer
01000100011 01110 0000000000000000lw $t0, 0($t6)
01001000000 01000add $t1, $t0, $t0 01000 10000000000
addi $t6, $zero, 5000 001000 00000 01110
001000 00000 01110 ...
100011 01110 01000 ...
000000 01000 01000 ...
101011 01110 01001 ...
Executable file
0001001110001000
Start 2x speed
1/3/2019 7.1. Machine instructions
https://learn.zybooks.com/zybook/FIUCDA3103CickovskiFall2018/chapter/7/section/1 9/9
PARTICIPATION
ACTIVITY 7.1.8: Executable les.
1) An assembly program is placed into a
processor's instruction memory.
2) An executable le is convenient for
humans to read.
3) A processor executes each machine
instruction one at a time (conceptually).
01001101011 01110 0000000000000000
sw $t1, 0($t6)
IM CPU
001000 00000 01110 ...
100011 01110 01000 ...
000000 01000 01000 ...
101011 01110 01001 ...
True
False
True
False
True
False
Provide feedback on this section

Navigation menu