02_Assembly

02_Assembly - Assembly Language Readings: 2.1-2.7,...

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

View Full Document Right Arrow Icon
Assembly Language Readings: 2.1-2.7, 2.9-2.10, 2.14 Green reference card, B.10 Assembly language Simple, regular instructions – building blocks of C, Java & other languages Typically one-to-one mapping to machine language Our goal Understand the basics of assembly language Help figure out what the processor needs to be able to do 9 Not our goal to teach complete assembly/machine language programming Floating point Procedure calls Stacks & local variables Aside: C/C++ Primer struct coord { int x, y; }; /* Declares a type */ struct coord start; /* Object with two slots, x and y */ start.x = 1; /* For objects “.” accesses a slot */ struct coord *myLoc; /* “*” is a pointer to objects */ myLoc = &start; / *“&” returns thing’s location */ myLoc->y = 2; /* “->” is “*” plus “.” */ int scores[8]; /* 8 ints, from 0. .7 */ scores[1]=5; /* Access locations in array */ int *index = scores; /* Points to scores[0] */ index++; /* Next scores location */ x y 10 index++; (*index)++; /* “*” works in arays as well */ index = &(scores[3]); /* Points to scores[3] */ *index = 9; 0 1 2 3 4 5 6 7
Background image of page 1

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

View Full DocumentRight Arrow Icon
MIPS Assembly Language The basic instructions have four components: Operator name Destination 1 st operand 2 nd operand add <dst>, <src1>, <src2> # <dst> = <src1> + <src2> sub <dst>, <src1>, <src2> # <dst> = <src1> - <src2> Simple format: easy to implement in hardware More complex: A = B + C + D – E 11 Operands & Storage For speed, CPU has 32 general-purpose registers for storing most operands For capacity, computer has large memory (256MB+) Computer Processor Control Datapath Memory Devices Input Output GPRs 12 Load/store operation moves information between registers and main memory All other operations work on registers
Background image of page 2
Registers 32 registers for operands Register Name Function Comment $0 $zero Always 0 No-op on write $1 $a Reserved for assemble Don’tuseit $at Reserved for assembler Don t use it! $2-3 $v0-v1 Function return $4-7 $a0-a3 Function call parameters $8-15 $t0-t7 Volatile temporaries Not saved on call $16-23 $s0-s7 Temporaries (saved across calls) Saved on call $24-25 $t8-t9 Volatile temporaries Not saved on call $26-27 $k0-k1 Reserved kernel/OS Don’t use them $28 $gp Pointer to global data area 13 $29 $sp Stack pointer $30 $fp Frame pointer $31 $ra Function return address Basic Operations (Note: just subset of all instructions) Mathematic: add, sub, mult, div add $t0, $t1, $t2 # t0 = t1+t2 Unsigned (changes overflow condition) addu $t0, $t1, $t2 # t0 = t1+t2 Immediate (one input a constant) addi $t0, $t1, 100 # t0 = t1+100 Logical: and, or, nor, xor and $t0, $t1, $t2 # t0 = t1&t2 Immediate andi $t0, $t1, 7 # t0 = t1&b0111 Shift: left & right logical, arithmetic sllv $t0, $t1, $t2 # t0 = t1<<t2 Immediate sll $t0, $t1, 6 # t0 = t1<<6 14 Example: Take bits 6-4 of $t0 and make them bits 2-0 of $t1, zeros otherwise:
Background image of page 3

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

View Full DocumentRight Arrow Icon
Memory Organization Viewed as a large, single-dimension array, with an address.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/11/2010 for the course ECE 125 taught by Professor Chang during the Spring '10 term at Eastern.

Page1 / 14

02_Assembly - Assembly Language Readings: 2.1-2.7,...

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

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