0

The program is designed to subtract the first input by the second and if the result is positive or zero then input 1 is bigger (or the same) so input 1 is outputed first. This all works fine when the first number is bigger but when the first number is smaller it still runs the 'if positive' loop even though the result of the subtraction is negative. I don't understand why this happens but I hope someone with more experience with this program can help.

        INP
        STA VONE 
        INP
        STA VTWO
        LDA VONE
        SUB VTWO
        STA NUM
        LDA NUM
BTOS    LDA VONE
        OUT
        LDA VTWO
        OUT
        BRA LOOP
        BRP BTOS
        LDA VTWO
        OUT
        LDA VONE
        OUT
        BRA LOOP2

The BRA LOOP is a different part of the program, which works correctly, so you can ignore it.

Liwa
  • 116
  • 12
Huhmit
  • 1
  • 1
  • 3

1 Answers1

1

What you will want to do here is take away one number, then use both the BRA and BRP commands to see which one is larger.

This is the amended code:

    INP
    STA VONE 
    INP
    STA VTWO
    LDA VONE
    SUB VTWO
    BRP BTOS
    BRA BTOS2
BTOS LDA VONE
    OUT
    LDA VTWO
    OUT
BTOS2 LDA VTWO
    OUT
    LDA VONE
    OUT
VONE    DAT
VTWO    DAT
badarshahzad
  • 1,227
  • 16
  • 25
Liwa
  • 116
  • 12