L20-AssemblyProg1_BobEdit

L20-AssemblyProg1_BobEdit - Spring 2009 ECE 18-240...

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

View Full Document Right Arrow Icon
Spring 2009 ECE 18-240 Structure and Design of Digital Systems LEC 20: Assembly Language Programming 2 Bob Koutsoyannis & Bill Nace & Don Thomas Electrical & Computer Engineering Carnegie Mellon University LEC 20
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 SPR09 18-240 LEC18 18-240: Where are we. ..? 1 Handout: Lec20 Sigh of relief that Midterm2 is over Recitation: Lab Quiz
Background image of page 2
3 F09 18-240 L20 Assembly Programming, part 1 Get a better idea about … How to write asm code that does not execute in order How to do loops, ifs, while, etc Called: Control Flow uses condition codes & branches How some programs are faster than others Simple program timing analysis Special Registers PC (Program Counter) SP (Stack pointer) useful for Push/Pop, subroutine support Lec 20
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 F09 18-240 L20 Review Basic instruction types load and store this is the only way to get information from and to the memory although later we’ll add other instructions to this category arithmetic these instructions perform operations on values in registers (no memory accesses) branches these are used to break up the sequential nature of instruction execution used for if-then-else, and loops rely upon condition codes! Pseudo operations these aren’t really machine instructions (thus the word pseudo) these are instructions to the assembler
Background image of page 4
5 F09 18-240 L20 How to get Programs into Memory x = 0; if (y == 1) z = *p; Software in high- level language Processor hardware Assembly Language one-to- one textual representation of machine instructions Compiler Assembler Machine code Machine code — the 1’s and 0’s of the instructions that are understood by the processor. (a.k.a. machine instructions) Instructions Data
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 F09 18-240 L20 Quick review: the human assembler What addresses do the following instructions reside in? lda R2, Woz ldi R3, Woz What is the machine code? What value is loaded .ORG $1000 lda R2, Woz ldi R3, Woz ... ; other instructions .ORG $3000 Woz .DW $1987 addr contents 1000 1001 1002 1003 ... 3000 lda Woz ldi Woz 0412 3000 0C1B 3000 1987
Background image of page 6
D = B + C + (E-3) .ORG $2000 arith lda R0,B ;R0 ← B lda R1,C ;R1 ← C lda R2,E ;R2 ← E ldi R3,$3 ;R3 ← constant 3 add R1,R0 ;R1 ← B + C sub R2,R3 ;R2 ← E - 3 add R1,R2 ;R1← (B+C) + (E -3) sta D,R1 ;D ← R1 stop .ORG $3000 D .DW $0 B .DW $1 C .DW $3 E .DW $9 7 F09 18-240 L20 Ex A: Simple Arithmetic Assign memory and initialize the variables Have to get data into the P18240 Then we can do the arithmetic Finally, put the result back into mem
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 F09 18-240 L20 Ex B: Simple If-Then if (X <= Y) Y = Y - Z; {next instruction} get the data into registers Check the condition execute the ―then‖ part .ORG $2000 test lda R0,X ;R0 ← X lda R1,Y ;R1 ← Y ; compare X, Y by doing X - Y ; if X == Y, zero flag set, do the then ; if X < Y, neg flag set, do the then ; else just go do next instr then lda R3,Z ; R3 ← Z sub R1,R3 ; R1 ← Y - Z sta Y,R1 ; Y ← R1 next stop ;what ever… .ORG $3000 X .DW $5 Y .DW $2 Z .DW $7
Background image of page 8
9 F09 18-240 L20 Ex C: If-Then-Else if (X == Y)
Background image of page 9

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

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

This note was uploaded on 05/10/2011 for the course ECE 18240 taught by Professor Hoe during the Fall '08 term at Carnegie Mellon.

Page1 / 39

L20-AssemblyProg1_BobEdit - Spring 2009 ECE 18-240...

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

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