Top Banner
MIPS Architecture • Topics What resources MIPS assembly manipulates CPU (Central Processing Unit) ALU (Arithmetic & Logical Unit), Registers – Memory – I/O How are resources being manipulated Data transfer Arithmetic Operations • I/O
16

MIPS Architecture Topics What resources MIPS assembly manipulates CPU (Central Processing Unit) ALU (Arithmetic Logical Unit), Registers Memory I/O.

Jan 18, 2018

Download

Documents

Data Transfer X = A[1] (load word) Compute (address of A + index offset in bytes) Transfer the effective address to Memory Address Register (MAR) Read memory into Memory Data Register (MDR) Transfer to CPU register A[1] = X (store word) Transfer register to MDR Computer effective address to MAR Write
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: MIPS Architecture Topics What resources MIPS assembly manipulates CPU (Central Processing Unit) ALU (Arithmetic  Logical Unit), Registers Memory I/O.

MIPS Architecture• Topics– What resources MIPS assembly manipulates– CPU (Central Processing Unit)

– ALU (Arithmetic & Logical Unit), Registers

– Memory– I/O

– How are resources being manipulated• Data transfer• Arithmetic Operations• I/O

Page 2: MIPS Architecture Topics What resources MIPS assembly manipulates CPU (Central Processing Unit) ALU (Arithmetic  Logical Unit), Registers Memory I/O.

MIPS Architecture

CPU

Page 3: MIPS Architecture Topics What resources MIPS assembly manipulates CPU (Central Processing Unit) ALU (Arithmetic  Logical Unit), Registers Memory I/O.

Data Transfer• X = A[1] (load word)

• Compute (address of A + index offset in bytes)

• Transfer the effective address to Memory Address Register (MAR)

• Read memory into Memory Data Register (MDR)

• Transfer to CPU register• A[1] = X (store word)

• Transfer register to MDR• Computer effective address to

MAR• Write

Page 4: MIPS Architecture Topics What resources MIPS assembly manipulates CPU (Central Processing Unit) ALU (Arithmetic  Logical Unit), Registers Memory I/O.

Arithmetic Operation• X =X+Y

• Transfer X, Y (in registers) to ALU (Arithmetic & Logic Unit)

• Add• Transfer the sum to a register

Page 5: MIPS Architecture Topics What resources MIPS assembly manipulates CPU (Central Processing Unit) ALU (Arithmetic  Logical Unit), Registers Memory I/O.

Assembly Programmer’s View

•Programmer-Visible State– Program Counter (PC)

• Address of next instruction

– Location Counter (LOC)– Register File

• Heavily used program data– Condition Codes

• Store status information about most recent arithmetic operation

• Used for conditional branching

Memory

Object CodeProgram DataOS Data

Addresses

Data

Instructions

Stack

– Memory• Byte addressable array

(organized in words)• Code, user data, (some) OS data• Includes stack

PCRegisters

CPU

ConditionCodes

Page 6: MIPS Architecture Topics What resources MIPS assembly manipulates CPU (Central Processing Unit) ALU (Arithmetic  Logical Unit), Registers Memory I/O.

Assembly Instruction

• label: instruction operand {,operand} #comments

• label – a place holder: address• Instruction – operation to perform• Operand – data or target of the

operation• Register• Literal constant• Memory address

Page 7: MIPS Architecture Topics What resources MIPS assembly manipulates CPU (Central Processing Unit) ALU (Arithmetic  Logical Unit), Registers Memory I/O.

Registers• 32 32-bit Registers

– Zero: always 0, and cannot be modified– $t0 -- $t9: General purpose– $a0 -- $a3: General purpose (arguments)– $s0 -- $s7: General purpose– $v0, $v1: General purpose– $sp: stack pointer– $ra: return address

Page 8: MIPS Architecture Topics What resources MIPS assembly manipulates CPU (Central Processing Unit) ALU (Arithmetic  Logical Unit), Registers Memory I/O.

Data Transfer• From the viewpoint of registers• Moving Data

lw Dest, Source:– Move 4-byte (“long”) word– Constant or from memory address– To Dest register

• Operand Types– Immediate: Constant integer data

• 0xff for hex constant• Otherwise, decimal

– Memory: 4 consecutive bytes of memory• Various “address modes”

– Register: One of 32 integer registers

Page 9: MIPS Architecture Topics What resources MIPS assembly manipulates CPU (Central Processing Unit) ALU (Arithmetic  Logical Unit), Registers Memory I/O.

Operand Addressing

– No instruction for reg-to-reg transfer– Cannot do memory-memory transfers with single instruction

– sw instruction violates (dest, source) spec of operands

Imm

Reg

Mem

Reg

Reg

Mem

Reg

Source Destination

li $t1, 0x4

la $t1, A

sw $t1,A($t2)

lw $t1,A($t2)

C Analog

temp = 0x4;

temp2 = &A;

A[n] = temp;

temp = A[n];

Addr

Page 10: MIPS Architecture Topics What resources MIPS assembly manipulates CPU (Central Processing Unit) ALU (Arithmetic  Logical Unit), Registers Memory I/O.

I/O InstructionsService Call

code ($v0)

Arguments (input) Results

print integer

1 $a0 = integer signed decimal integer printed in console window

print string 4 $a0 = address of string string printed in console window

Read integer

5 (none) $v0 holds integer that was entered

Read string 8 $a0=address to store $a1= length limit

characters are stored

exit 10 (none) Ends the program

– http://courses.missouristate.edu/kenvollmar/mars/help/syscallhelp.html

Page 11: MIPS Architecture Topics What resources MIPS assembly manipulates CPU (Central Processing Unit) ALU (Arithmetic  Logical Unit), Registers Memory I/O.

.dataprompt: .asciiz “Enter an integer to square:\n“ # message area

.textmain: # printf(“Enter an integer to square: \n”);

la $a0, prompt # get the address of the message to $a0li $v0, 4 # read to display the messagesyscall

# scanf(“%d”, x);li $v0, 5 # read an integer into $v0syscall

mul $a0, $v0, $v0 # squared input value, save in $a0

# printf(“%4d”, (x*x));li $v0, 1 # print the squared valuesyscall

printf(“Enter an integer to square: \n”);scanf(“%d”, x);printf(“%4d”, (x*x));

Square an input Number

Page 12: MIPS Architecture Topics What resources MIPS assembly manipulates CPU (Central Processing Unit) ALU (Arithmetic  Logical Unit), Registers Memory I/O.

• Directives (Establish initial data structure)• .ascii (store string in memory with no null-termination)• .asciiz (store string in memory with null termination)• .byte b1,..,bn• .word w1,..,wn• .word w:n (store w into n successive words)• .space n

• .data data segment• .text assembly instructions

Directives

Page 13: MIPS Architecture Topics What resources MIPS assembly manipulates CPU (Central Processing Unit) ALU (Arithmetic  Logical Unit), Registers Memory I/O.

• MIPS instructions• http://www.mrc.uidaho.edu/mrc/people/jff/digital/

MIPSir.html• www.cs.uml.edu/~kim/203/mips_instr.xls

• MIPS Reading• www.cs.uml.edu/~kim/203/mips.doc

• MARS MIPS simulator• http://courses.missouristate.edu/KenVollmar/MARS/

Resources

Page 14: MIPS Architecture Topics What resources MIPS assembly manipulates CPU (Central Processing Unit) ALU (Arithmetic  Logical Unit), Registers Memory I/O.

Operand Addressing

– No instruction for reg-to-reg transfer– Cannot do memory-memory transfers with single instruction

– sw instruction violates (dest, source) spec of operands

Imm

Reg

Mem

Reg

Reg

Mem

Reg

Source Destination

li $t1, 0x4

la $t1, A

sw $t1,A($t2)

lw $t1,A($t2)

C Analog

temp = 0x4;

temp2 = &A;

A[n] = temp;

temp = A[n];

Addr

Page 15: MIPS Architecture Topics What resources MIPS assembly manipulates CPU (Central Processing Unit) ALU (Arithmetic  Logical Unit), Registers Memory I/O.

Addressing Modes• Addressing Modes• Indirect (R) Mem[Reg[R]]– Register R specifies memory address lw $t1, ($t2)

• Indexed D(R) Mem[Reg[R]+D]– Register R specifies start of memory block– Constant displacement D specifies offset lw $t1, 8($t2)

Page 16: MIPS Architecture Topics What resources MIPS assembly manipulates CPU (Central Processing Unit) ALU (Arithmetic  Logical Unit), Registers Memory I/O.

.dataarray: .word 0x37, 0x55, 0xF

.textla $s0, arrayla $s1, array+4la $s2, 8($s0)

li $a0, 4

lw $t0, 0($s0) lw $t3, array($a0)

lw $t1, 8($s0)lb $t2, ($s0)

Example