Search code examples
assemblyintel-8080

Read register pair by bits - assembly i8080


I have a hexadecimal value stored in register pair B. And I want to read it by chars. For example in B is 322 (hexadecimal) I want to have in accumulator 3 then 2 and then 2 (in ASCII). Is it somehow possible? Or is it possible to store this register pair into "string". By string I mean this line-> my_string: ds 30 I'm really new to assembly.


Solution

  • As I recall, "register pair B" is made up of the B and C registers. C is the low 8 bits, and B contains the high 8 bits. So if you have a value in BC and you want to get the hexadecimal digits (4 digits), the procedure is something like:

    1. MOV A,B
    2. Shift A right 4 places (see below). This puts the high 4 bits of the number into the low 4 bits of A, and clears the high 4 bits of A. So you have a number from 0 to 15.
    3. Convert that value to a hex digit (0-9, A-F). I seem to remember that there was some non-obvious way to do this, but I don't remember what it was.
    4. Output that value (or save it in memory to be output later).
    5. MOV A,B
    6. ANI 0x0F -- This zeros the high 4 bits, giving you the low four bits of the high byte.
    7. Do steps 3 and 4.
    8. MOV A,C
    9. Do steps 2, 3, and 4
    10. MOV A,C
    11. Do steps 3 and 4

    It's been a long time since I wrote any 8080 code, so I'm not going to confuse you with broken code here. The steps I outline above will do what you need.

    Note that my use of 0x0F might not be the correct syntax for your assembler. I'm trying to and immediate with the decimal value 15, or hexadecimal value F. I don't know how your assembler expresses hexadecimal constants.

    I don't think the 8080 had a shift instruction. It did, however, have rotate instructions. So what you do instead of shift right 4 places is rotate right four places and then mask the low 4 bits. That is:

    RAR
    RAR
    RAR
    RAR
    ANI 0x0F