Skip to the content. Back to Week 4

LMC Questions

+ Please highlight your answers in 'amend' questions
  1. Amend the following program so that it adds together three numbers:
    ~         INP
    ~         STA Num1
    ~         INP
    ~         ADD Num1
    +         STA Num1
    +         INP
    +         ADD Num1
    ~         OUT
    ~ Num1    DAT
    
  2. Write a program that takes in 2 numbers and subtracts the second from the first:
    >        INP
            STA 0
            INP
            SUB 0
            OUT
    
  3. Write a program that outputs the larger of two numbers:
    >        INP
            STA 0
            INP
            SUB 0
            BRP 8
            LDA 0
            OUT
            HLT
            ADD 0
            OUT
    
  4. BRZ branches when 0 is stored in the accumulator.
    Write a program that takes in two numbers and outputs 1 if they are the same, and 0 if they are different.
    >        INP
            STA 0
            INP
            SUB 0
            BRZ 9
            LDA 7
            OUT
            HLT
            DAT 1
            LDA 8
            OUT