assemblyx86-16dot-matrix

MDA-8086 8*8 Dot matrix display code segment explaination


I have a code that display 'A' in the dot matrix display of MDA-8086. Here is it:

ORG 1000H
MOV AL, 10000000B       ;Activate Signal
OUT 1EH, AL             ;Writing Activate signal to  Control Register
MOV AL, 11111111B       ;Off Signal
OUT 18H, AL             ;Writing off signal to Port A
L1: MOV SI, OFFSET FONT ;Assigning source address to Memory address/                            ;offset of FONT Variable
    MOV AH, 00000001B
L2: MOV AL, BYTE PTR CS:[SI]
    OUT 1AH, AL
    MOV AL, AH
    OUT 1CH, AL
    CALL TIMER
    INC SI
    CLC
    ROL AH, 1
    JNC L2
    JMP L1
    INT 3
TIMER: MOV CX, 300
TIMER1: NOP
        NOP
        NOP
        NOP
        LOOP TIMER1
        RET
FONT: DB 11111111B
      DB 11001001B
      DB 10110100B
      DB 10110110B
      DB 10110110B
      DB 10110110B
      DB 10000000B
      DB 11111111B

Now I don't get these lines; MOV SI, OFFSET FONT and MOV AL, BYTE PTR CS:[SI]. can anyone tell me what these lines do?
Edit:

I also want to know how DB is working in FONT and how each DB is evaluated.


Solution

  • Now I don't get these lines

    16- and 32-bit code of x86 CPUs always use two numbers to specify the address of something stored in memory:

    The segment and the offset.

    The segment describes some region in memory.

    The "real" address of some item in memory can be calculated by:

    (address of the first byte of the segment) + offset
    

    The CS register is normally read-only. It contains the segment which contains the instruction which is currently executed.

    The MOV SI, OFFSET FONT instruction will now write the offset of the data following the FONT: label to the SI register.

    The MOV AL, BYTE PTR CS:[SI] instruction will read one byte from the memory into the register AL. The byte is read from the following address:

    (address of the first byte of the CS segment) + (value of register SI)
    

    Because the FONT: label is in the same segment as the instruction itself (CS) and SI contains the offset of FONT: the address calculated this way is the address of the first byte of FONT:.

    In other words: The instruction loads the first byte of FONT: into the register AL.

    (When the instruction is called the second time the second byte of FONT: will be loaded because SI has been incremented.)

    I also want to know how DB is working ...

    DB is not an instruction.

    DB tells the assembler to write a byte with a certain value into the memory instead of an instruction.

    So the following (non-sense) code:

    mov ax, 1
    db 10
    mov ax, 2
    

    ... means that there shall be the byte with the value 10 between the two mov instructions.

    how DB is working in FONT

    The 8 bytes (here not specified as decimal but as binary numbers) are stored at the memory location named FONT:.