0

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.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847

1 Answers1

2

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:.

Martin Rosenau
  • 17,897
  • 3
  • 19
  • 38
  • So, the bytes written by `DB` are stored in code segment? And, I've seen very few elaborate answer like yours. So thanks. – Ahashan Alam Sojib Dec 09 '17 at 17:51
  • 1
    @AhashanAlamSojib: `db` emits a byte at the current position in the current section. [Syntactically, it's just like any other instruction](https://stackoverflow.com/questions/46513413/x86-asm-dd-being-used-as-an-instruction) (so you could call it a pseudo-instruction). Remember that assembly language doesn't have "variables" or anything, it's just a language for conveniently describing which bytes you want where. Labels let you get the assembler to calculate offsets and stuff, but still each line just makes the assembler emit some bytes into the output file. – Peter Cordes Dec 09 '17 at 17:56