:
This message was edited by Starburn at 2002-10-4 5:37:27
: Ahh, but ... an 8bit register cannot be added to a 16 bit one...
: (pascals inline assembler will give a compile error),
: And also, I was using a char as a test, I needed the memory location so when I change it to a string/array of chars, they will be easy to access as they will be in consectutive memory locations.. unless theres another way to do it easier, with a string.
:
:
: :(
:
: Also, why 160 into bl? Is this for 80x25 screen mode? And one more question .. why 0b800h ? does the h represent hexidecimal?.. and so whats the 0 for?
:
: Thanks.
:
:
:
:
You are right, you cannot add 8 and 16 bit registers, but
you can 16 and 16 bit as long as you clear upper half of
the one with 8-bit value.
Number 160 had to do with the way text screen is organized.
there are 80x25 characters displayed, however one line is
not 80 but 160 byte long because of attrib characters ("colors"):
LINE0: attrib0,char0, attrib1, char1, ... , attrib79, char79,
LINE1: attrib80,char80, attrib81,char81, ... , attrib159,char159,
LINE2: attrib160,char160, etc.
So here is working code
procedure putchar(x,y:byte; c:char); assembler;
asm
push es { save ES on stack }
mov AX, 0b800h
mov ES, AX { point ES to text screen }
xor AX, AX
mov AL, y { AX = y }
xor BX, BX
mov bl, 80
mul bl { AX = y*80 }
xor bx, bx
mov bl, x
add ax, bx { AX = y*80+x }
add ax, ax { AX = (y*80+x)*2 }
mov di, ax { ES:DI points to screen position }
mov al, c { load character into AX }
stosb { write one char to screen }
pop es { restore original ES from stack }
end;
begin
asm mov ax,3; int 16 end;
putchar ( 0,0,'A');
putchar ( 10,10,'B');
putchar ( 40,12,'C');
readln;
end.
Iby