CSC 215 Weekly Assignments: Week 6

CSC 215


Overview

This week we will move from writing programs in hex to writing them in assembly language.

Thursday, October 8th

Classwork

We'll start today by comparing notes on how things went assembling the only captial letters and add two 16 bit integer programs. Then we will pair up again for our next project:

  • Pair A: Giselle and Stephan
  • Pair B: Mason and Dimitri
  • Pair C: Waleed and Delaine
  • Pair D: Nathan and Chris

Project: Using the Stack

Complete each of the following tasks:

  1. Read Stack (abstract data type), and discuss this with your partner. Explain to each other what a stack is, and quiz each other on the two main stack operations, on what LIFO means, and what causes stack underflow and stack overflow.
  2. Assemble and run the following program:

    ; SP WATCHER
    ; Demonstrates PUSH/POP and SP movement.
    ; Stack initialized to 2400H.
    ; Watch SP and memory at 23F0H-23FFH during single-step.
    
            ORG  0000H
    
    START:  LXI  SP, 2400H    ; 31 00 24  - Initialize stack pointer
            LXI  H, 2400H     ; 21 00 24  - H = last SP value (for reference)
    
    ; --- Load known values into register pairs ---
            LXI  B, 1111H     ; 01 11 11  - BC = 1111
            LXI  D, 2222H     ; 11 22 22  - DE = 2222
            LXI  H, 3333H     ; 21 33 33  - HL = 3333
    
    ; --- PUSH all three pairs ---
            PUSH B            ; C5        - SP: 2400 -> 23FE, mem[23FE]=11, mem[23FF]=11
            PUSH D            ; D5        - SP: 23FE -> 23FC, mem[23FC]=22, mem[23FD]=22
            PUSH H            ; E5        - SP: 23FC -> 23FA, mem[23FA]=33, mem[23FB]=33
    
    ; --- PUSH the flags/accumulator ---
            MVI  A, 44H       ; 3E 44     - A = 44
            PUSH PSW          ; F5        - SP: 23FA -> 23F8, mem[23F8]=44, mem[23F9]=flags
    
    ; --- Now POP them back in reverse order ---
            POP  PSW          ; F1        - SP: 23F8 -> 23FA, A = 44
            POP  H            ; E1        - SP: 23FA -> 23FC, HL = 3333
            POP  D            ; D1        - SP: 23FC -> 23FE, DE = 2222
            POP  B            ; C1        - SP: 23FE -> 2400, BC = 1111
    
    ; --- Done: SP should be back at 2400, registers restored ---
            HLT               ; 76
    
            END
    

    Study this program and discuss it with your partner until you convince each other you know how it works.

  3. Use your new understanding of the stack to write a program that is given a null-terminated character string as input and produces a string with characters in reverse order as output.
  4. Be prepared to present your programs in class next Wednesday. In your presentation you should do a step-by-step whiteboard trace of your program.

Homework / Evaluation

Monday, October 5th

Classwork

As we discussed last class, this week we will begin using the Python Intel 8080 Mini Cross-Assembler to write out programs for our Altair computers.

During class today, rewrite the null-terminated string and adding two 32-bit integer programs in assembly language. Compare the output with what you had in the previous version.

Homework / Evaluation

You'll earn credit for having these programs in your git repos.