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.
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:
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 theFONT:
label to theSI
register.The
MOV AL, BYTE PTR CS:[SI]
instruction will read one byte from the memory into the registerAL
. The byte is read from the following address:Because the
FONT:
label is in the same segment as the instruction itself (CS
) andSI
contains the offset ofFONT:
the address calculated this way is the address of the first byte ofFONT:
.In other words: The instruction loads the first byte of
FONT:
into the registerAL
.(When the instruction is called the second time the second byte of
FONT:
will be loaded becauseSI
has been incremented.)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:
... means that there shall be the byte with the value 10 between the two
mov
instructions.The 8 bytes (here not specified as decimal but as binary numbers) are stored at the memory location named
FONT:
.