Search code examples
assemblyintel-8080

What do these set of instructions do?


What does this code mean?

There are my comments. I may be wrong. But I think so.

        PUSH    H       ;There we push data from H-register to the stack.
        LXI     H, OFFF ;I can't understand... Why OFFF, not 0xFFF?
REP:    DCX             ;It decrements passed register. But there's nothing to decrement. Is it correct?
        MVI     A, OO   ;Again... What do two O mean?
        CMP     H       ;CMP takes two arguments. Why does it take one there?
        JMP     REP     ;It's a kind of loop. Jumping to the REP label.
        POP     H       ;This instruction pops data from the stack to the H register.
        RET             ;Return to the caller.

I've never met constructions like OFFF, OO. What does it mean?

What does this code do? Which is the main purpose might be?

Which model of processor it might be? How do you think?


Solution

  • Where did you get this code? That's usually a big hint to what architecture it's for. It could be 8080, I think; it has A and H registers (https://en.wikipedia.org/wiki/Intel_8080), and many instruction mnemonics similar to its descendent, 8086.

    Re: the hex constants, presumably this assembler defaults to hex for numeric literals, and load-immediate into eXtended register pair (lxi) takes a 16-bit immediate so they're writing it with 4 hex digits. (That's a 0, not an O).

    Same for mvi, mov-immediate to 8-bit register takes an 8-bit immediate, and they chose to write explicit zeros for both halves. The leading 0 on 0FFF is also necessary to disambiguate from a symbol name.


    Re: other mysteries, look at an instruction-set reference for 8080 to see what DCX does. (Spoiler alert: I checked and dcx does indeed require an operand. Unless some assemblers have a default 16-bit register-pair to decrement? Presumably HL aka H, the loop counter?)

    But cmp compares the explicit operand against the accumulator (A); implicit operands are how many instructions could be only 1 byte: https://pastraiser.com/cpu/i8080/i8080_opcodes.html