Notes:
(Adapted from Day 7) Memory addressing:
Every
Byte
has an address, but for most operations, we think of the memory in Word
(2-byte) size chunks, because that's what move in and out of registers,
mostly, and that's the size we store numbers in.
Weirdness. LDBYTE takes the most significant
byte of the Word at the address and loads it into the least
significant
byte in the register. STBYTE takes the least significant
byte
in the register and stores it in the most significant byte of
the
Word at the address.
(Oddities about tracing: Store ---, d: the operand is not the
number that's getting stored, but the memory contents before the
store.
The xxBYTE operands show up as words, though only the left hand byte is
in play )
From Day 9:
Immediate addressing p.201-3, addressing mode
specifier 000,
assembly language i
Direct addressing: the operand specifier was the address
of
the operand. Oprnd = Mem[OprndSpec]
Immediate addressing: the operand specifier is
itself the operand. Oprnd = OprndSpec
LDA 0x001B, d ; loads the word at memory location 001b into A.
LDA 0x001B, i ; loads the
word 001B into A.
Saves computer work: Direct
addressing:
Fetch the operand specifier. Then fetch the word at that address,
load it into A.
Immediate
addressing: Fetch the operand specifier. Load it into A.
Saves programmer work: Adding 1 to register
A? AddA 1, i .
Don't have to store data with .word 1.
Charo 0x0041, i == Charo 0x41, i == Charo 'A', i == 50 0041 outputs A.
Charo 0x0A, i outputs
linefeed.
Easier for now for outputting a string than making all the individual
byte addresses.
' ' character data. Contains 1byte (e.g. for
Charo)
LDA 'B',
i loads 0x0042 into
A. (fills in upper byte with 0's.)
Immediate operands are like Const values in C++. Cannot
change as the program runs.
Also, C++ shows its C lowlevel origins:
a++ Assembly level,
AddA 1, i
________
From Day 11:
Keeping track of addresses is a royal pain. Next step toward
readability,
toward a higher level language:
SYMBOLS. Syntax: Letter followed by letters
or numbers, no spaces. 8 or fewer characters. Case
sensitive.
A symbol is an alphanumeric label for
-- an address inputnum:
.block 2 ;for data
storage address
(suppose it's at address 0x0003)
main:
deci 0x0003, d ;for target of a
branch
(suppose it's at address 0x0007)
Symbol followed by colon: precedes the instruction or memory block to
be
labeled. (pp.
209-11)
--a constant value (e.g. to use in
immediate
mode) in front of .Equate <constant
value>
(pp.223-4)
linefeed: .equate 0x0A ; like C++
constant
The symbol (without the colon) can be used wherever the
number giving the address/constant
value would be used.
main:
deci inputnum, d ;for target of a branch
These are listed in a Symbol Table at the end of the Assembler
Listing
Symbol Value
inputnum 0x0003
main 0x0007
linefeed 0x000A
Then you can say STA inputnum, d instead of STA
0x0003
BR main
instead of BR 0x0007
CHARO
linefeed, i instead of CHARO 0x0A
(You can also say BR linefeed--the computer doesn't
care what you use the number for! It will branch to location
0x000A)
- - - - - - - - - - Program
without formatting, to paste to pep- - - - -
- - - - - - - - -
;Program to use Deci and Deco, Day 11 from Day 9 Using Symbols &
Immediate Addressing
BR
main ; was 0x
0007 ; branch around data! PC<--0007
; DATA up front
one: .equate 0x0001
; was .word 0x0001 (don't need memory using
immediate, addresses move up 1); 1 for
adding to 1's complement
inputnum: .block 2 ; 2 bytes=
a word space for the decimal input
negnum: .block 2
; a word space for the negative of the input.
linefeed: .equate 0x0A ; was
.byte 0x0A, gone using
immediate ; new line
; Now INSTRUCTIONS
main: deci inputnum ,d ;was deci
0x0005 ,d Input a decimal number
deco
inputnum, d ; was deco 0x0005, d ;output the
same decimal number
charo linefeed, i ; was charo 0x0A,
i ; new line
lda
inputnum, d ;was loada 0x0005
,d ; load into Accumulator
NotA
;1's complement
AddA one,
i ;was AddA
0x0001, i ; Add 1 for 2's complement
Sta
negnum,d ;was Storea 0x0005,d
;Store negative
deco negnum,d ; was
deco
0x0005,d
; output the negative
STOP
.END
- - - Same program Below without immediate mode, without Symbols-------
;Program which uses Deci and Deco, and BR to examine negatives
BR 0x000A ;
branch around data! PC<--000A
; DATA up front
.word 0x0001 ; 1 for adding to 1's complement
.block 2 ; 2 bytes= a word
space for the decimal input
.block 2 ; a word space for
the negative of the input.
.byte 0x0A ; new line
; Now INSTRUCTIONS
deci
0x0005 ,d ; Input a decimal number This instruction
is at address 000A
deco 0x0005,
d ;output the same decimal number
charo 0x0009, d ; new
line
lda
0x0005 ,d ; load into Accumulator
NotA
;1's complement
AddA 0x0003, d ;
Add 1 for 2's complement
Sta
0x0007,d ;Store negative
deco
0x0007,d
; output the negative
STOP
.END
| To Sievers Home Page |
CS225-Fall06/Day16.htm
|
|