CS225,  Fall 2006,  Friday Sept 29, Day 16 Hit reload!

(Re) Read  Chapter 5. Basic operations, data storage, symbols, addressing modes d and i.

HW Day 16, Due Monday Day 17
<>Please hand in the Listing from each program.   Please email me by 4 pm Sunday and tell me what you have succeeded in doing, what you have tried and had trouble with, and what you haven't started to try.   I'll make up Monday's work on the basis of that.
A) (from Day 7)  Use the program below comparing the Word and Byte ops.  a) Change the memory words to 4BCD and EF12, and predict what the output and the  entries in the 6 bytes of used memory will be after the program has run.  Then run it and check your results.  b) If I add the  instruction (ASRA) to the program just before STBYTEA, what has to change so that the other instructions run correctly (work on the same data as they do now)?
B)  Rewrite the program below comparing the Word and Byte ops, with Symbols (labels) for the 3 words of memory being used.
C)  Finish the Wallspace problem.  Use STRO to label your output.
Textbook, p. 231, # 25, # 27

D?).  Think about how to multiply, in binary.  Come in with a pseudocode or flowcharted algorithm.
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

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 )

Reinforcement for difference between the Word-size instructions (most) and the Byte-size ones (only LDBYTE and STBYTE, CHARI, CHARO):   (In Big-endian environment.)
- - - -  - - - - - - - - - - - - - - - - - - - - -
;Program to emphasize differences: output, load and store words, or bytes.
;Refresh memory after each store instruction
CHARO    0x0016, d   ; output first byte of first word
DECO       0x0016,d   ; output first word, as decimal
LDA           0x0016,d   ;load first word
LDBYTEA  0x0016,d   ;load first byte of first word
STA            0x0018,d   ;Store register right after first
LDA           0x001A,d   ;load Second word
STBYTEA  0x001A,d   ;Store lower (Least significant byte)
                    ;of reg. back OVER first byte of second word.
STOP
.WORD   0x506D     ;first word
.block       2                ; 2 bytes= a word space
.WORD   0xF1D0     ;second word
.END
- - - - - - - - - - - - - - - - - - - - -
What will have to be changed if I delete the CHARO instruction?
---------------------------------

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

Fig. 5.11 p. 202, examples of immediate addressing.

________
From Day 11:

Keeping track of addresses is a royal pain.  Next step toward readability, toward a higher level language:
SYMBOLSSyntax:  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)

Example,  Day 11, original day 8  (PEP-ready versions below)
;Program to use Deci and Deco,  Day 8 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; other addresses shift up 2); 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
= = = = = = = = = = = = = = = = =
Situation:  I am designing a wall, 20 feet long, that must have two doors in it.  I'll put the two doors at the ends of the wall. 
dddd____________________dddd   I'm interested in how much linear wall space will be left (for furniture, pictures, etc.); I have some leeway for the width of the doors.
So I want to calculate  wallspace = wall - 2door,  where wall is the width of the wall (20 feet) and door is the width of the door.

Write a PEP program to get the width of the door from Input, and output the wallspace.  Ignore for now the issue of prettyfying output .
Suggestions:  The wall width is constant for this program; use immediate mode for it.
       You have a compound computation (multiply by 2, subtract the result).  You may want a storage space for the intermediate result.
Do, discuss.

Extra time? Think about multiplication.

- - - - - - - - - - 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 
7pm, 9/28/06
This page belongs to Sally Sievers who is solely responsible for its content. Please see our statement of responsibility.