Lecture_8 - ECE 445 Computer Organization MIPS Addressing...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ECE 445 Computer Organization MIPS Addressing (Lecture #8) ECE 445 - Computer Organization 2 32-bit Immediate Operands ECE 445 - Computer Organization 3 32-bit Immediate Operands Most constant values are small- As such, 16-bit Immediate values are sufficient However, there are occasions for which larger constant values are required- In such cases, 32-bit Immediate values are used Given that the immediate field in an I-Format instruction is only 16 bits wide, how do we load a 32-bit constant into a register? ECE 445 - Computer Organization 4 32-bit Immediate Operands To load a 32-bit immediate value into a register:- First, load the upper 2 bytes of the register Using the Load Upper Immediate (lui) instruction- Then, load the lower 2 bytes of the register Using the Or Immediate (ori) instruction ECE 445 - Computer Organization 5 32-bit Immediate Operands For example, load the following 32-bit constant into register $s0: 0000 0000 0011 1101 0000 1001 0000 0000 61 2304 0000 0000 0011 1101 0000 0000 0000 0000 lui $s0, 61 0000 0000 0011 1101 0000 1001 0000 0000 ori $s0, $s0, 2304 Loads the upper 16 bits of register $s0 Clears the lower 16 bits of register $s0 Adds the lower 16 bits to register $s0 ECE 445 - Computer Organization 6 Bytes and Half-words ECE 445 - Computer Organization 7 Bytes and Half-words Most computers today use 8-bit bytes to represent characters.- ASCII represents 128 characters (using 7 bits) In addition, there exists 16- and 32-bit representations for characters.- UTF-16 (16-bit Unicode) can be used to represent a much larger character set. The MIPS Architecture includes instructions to move bytes (8 bits) and half-words (16 bits). ECE 445 - Computer Organization 8 Bytes and Half-words The byte and half-word instructions are: lb rt, offset(rs) Load Byte lh rt, offset(rs) Load Half-word lbu rt, offset(rs) Load Byte Unsigned lhu rt, offset(rs) Load Half-word Unsigned sb rt, offset(rs) Store Byte sh rt, offset(rs) Store Half-word Sign extends to 32-bits in rt Zero extends to 32-bits in rt Stores rightmost byte or half-word ECE 445 - Computer Organization 9 Bytes and Half-words String processing is a common application for which byte and half-word operations are used. ECE 445 - Computer Organization 10 The String Copy Function C code:- Null-terminated string void strcpy (char x, char y) { int i; i = 0; while ((x[i]=y[i])!='\0') i += 1; }- address of x $a0, address of y $a1- i $s0 ECE 445 - Computer Organization 11 The String Copy Function MIPS code: strcpy: addi $sp, $sp, -4 # adjust stack for 1 item sw $s0, 0($sp) # save $s0 add $s0, $zero, $zero # i = 0 L1: add $t1, $s0, $a1 # addr of y[i] in $t1 lbu $t2, 0($t1) # $t2 = y[i] add $t3, $s0, $a0 # addr of x[i] in $t3 sb $t2, 0($t3) # x[i] = y[i]...
View Full Document

Page1 / 29

Lecture_8 - ECE 445 Computer Organization MIPS Addressing...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online