22
Fall 2006 Lillevik 333f06- l4 1 University of Portland School of Engineering EE 333 Computer Organization Lecture 4 Assembly language programming ALU and memory instructions

Computer Organization Lecture 4

  • Upload
    gada

  • View
    53

  • Download
    2

Embed Size (px)

DESCRIPTION

Computer Organization Lecture 4. Assembly language programming ALU and memory instructions. Memory. Registers. ALU. MIPS: Programmers View. We will design a subset of this computer. Stack. Data. Program. Memory Usage. Memory divided into three separate regions or segments. - PowerPoint PPT Presentation

Citation preview

Page 1: Computer Organization Lecture 4

Fall 2006

Lillevik 333f06-l4 1University of Portland School of Engineering

EE 333

Computer OrganizationLecture 4

Assembly language programmingALU and memory instructions

Page 2: Computer Organization Lecture 4

Fall 2006

Lillevik 333f06-l4 2University of Portland School of Engineering

EE 333

MIPS: Programmers View

Memory

Registers

ALU

We will design a subset of this

computer

Page 3: Computer Organization Lecture 4

Fall 2006

Lillevik 333f06-l4 3University of Portland School of Engineering

EE 333

Memory Usage

Program

Data

Stack Memory divided into three separate regions or segments

Page 4: Computer Organization Lecture 4

Fall 2006

Lillevik 333f06-l4 4University of Portland School of Engineering

EE 333

Assembly programming

Sources files are assembled, then linked

This could be compiled

Page 5: Computer Organization Lecture 4

Fall 2006

Lillevik 333f06-l4 5University of Portland School of Engineering

EE 333

Assembler

• Purpose: translates a program statement (source file) into an address and data (object file)

• Steps (2-pass)– Create a symbol table– Use symbol table to generate instruction as a

binary number

• Execution: OS writes program into memory, transfers control, program runs, control returns to OS

Page 6: Computer Organization Lecture 4

Fall 2006

Lillevik 333f06-l4 6University of Portland School of Engineering

EE 333

Program statement syntax

• Generally, free-format• Comments: begin with sharp (#)

# this is a comment

• Labels: start the beginning of a line, end with colon (:)

start:loop:end:

Page 7: Computer Organization Lecture 4

Fall 2006

Lillevik 333f06-l4 7University of Portland School of Engineering

EE 333

Memory addresses

• Notation: c(rx)rx = register/base

c = constant/offset

• Examples100($t0) # EA = $t0 + 100

0x2f ($22) # EA = $22 + 0x 2f

($sp) # EA = $sp, c = 0

Page 8: Computer Organization Lecture 4

Fall 2006

Lillevik 333f06-l4 8University of Portland School of Engineering

EE 333

Directives

• Provides assembler information• Start with dot (.)• Examples

.text # start text segment

.data # start data segment

.asciiz # null terminated string

.word # insert word data

Page 9: Computer Organization Lecture 4

Fall 2006

Lillevik 333f06-l4 9University of Portland School of Engineering

EE 333

A typical line of code

label: opCode $destination, $operand1, $operand2, #comment

Examplesloop: li $t0, 2 # initialize $t0 = 2

calc: add $t1, $t3, $t1 # $t1 = $t3 + $t1

nop # do nothing

mult $s2, $s3 # hi:lo = $s2 x $s3

Page 10: Computer Organization Lecture 4

Fall 2006

Lillevik 333f06-l4 10University of Portland School of Engineering

EE 333

Program Structure

Labels

Program Directives

Page 11: Computer Organization Lecture 4

Fall 2006

Lillevik 333f06-l4 11University of Portland School of Engineering

EE 333

Simple Program

Page 12: Computer Organization Lecture 4

Fall 2006

Lillevik 333f06-l4 12University of Portland School of Engineering

EE 333

Let’s run the program

Page 13: Computer Organization Lecture 4

Fall 2006

Lillevik 333f06-l4 13University of Portland School of Engineering

EE 333

Write the program?Subtract 3 from 5 and leave in $t2

Page 14: Computer Organization Lecture 4

Fall 2006

Lillevik 333f06-l4 14University of Portland School of Engineering

EE 333

Instruction Classes

• Arithmetic and logic

• Load

• Store

• Comparison

• Branch and jump

• Data Movement

• Floating Point

Page 15: Computer Organization Lecture 4

Fall 2006

Lillevik 333f06-l4 15University of Portland School of Engineering

EE 333

Arithmetic and Logic

Instruction Example Meaningadd add $s1, $s2, $s3 $s1 = $s2 + $s3

sub sub $s1, $s2, $s3 $s1 = $s2 - $s3

add immediate addi $s1, $s2, 100 $s1 = $s2 + 100

multiply mult $s2, $s3 hi:lo = $s2 x $s3

divide div $s2, $s3 lo = $s2 / $s3

hi = $s2 mod $s3

Only registers used for operands

Page 16: Computer Organization Lecture 4

Fall 2006

Lillevik 333f06-l4 16University of Portland School of Engineering

EE 333

Loads (reg mem)

Instruction Example MeaningLoad word

(32 bits)

lw $s1, 100 ($s2) $s1 = mem[$s2 + 100]

Load byte unsigned

(8 bits)

lbu $s1, 100($s2) $s1 = mem[$s2 + 100]

Load address la $a0, data $a0 = address of data:

Load immediate li $t4, 18 $t4 = 0x 12

The point of reference is a register

Page 17: Computer Organization Lecture 4

Fall 2006

Lillevik 333f06-l4 17University of Portland School of Engineering

EE 333

Stores (reg mem)

Instruction Example MeaningStore word

(32 bits)

sw $s1, 100 ($s2) mem[$s2 + 100] = $s1

Store byte

(8 bits)

sb $s1, 100 ($s2) mem[$s2 + 100] = $s1

The point of reference is a register

Page 18: Computer Organization Lecture 4

Fall 2006

Lillevik 333f06-l4 18University of Portland School of Engineering

EE 333

Accessing Memory

• Use the la instruction to place address in a register

• Use the load/from & store/to address saved in the register

la $t0, var # $t0 = address of var:

lw $v1, ($t0) # $v1 = varsw $s0, 4($t0) # mem[var + 4] = $s0

Page 19: Computer Organization Lecture 4

Fall 2006

Lillevik 333f06-l4 19University of Portland School of Engineering

EE 333

Write the program?betaalpharesult 6

NOTE: data movement,mflo $reg

Page 20: Computer Organization Lecture 4

Fall 2006

Lillevik 333f06-l4 20University of Portland School of Engineering

EE 333

Page 21: Computer Organization Lecture 4

Fall 2006

Lillevik 333f06-l4 21University of Portland School of Engineering

EE 333

Write the program?Subtract 3 from 5 and leave in $t2

Page 22: Computer Organization Lecture 4

Fall 2006

Lillevik 333f06-l4 22University of Portland School of Engineering

EE 333

Write the program?betaalpharesult 6