ASM help
Posted: Mon May 05, 2003 12:50 pm
I am using Free Pascal as compiler.
So i wrote a Print Pascal String function...
Because pascal is buildup like this:
db Length, Text, db 0
and when using dynamic strings the compiler does this:
db 2, 'Hi000 .... to 255 ', db 0
So the only chose is to write a print function to deal with this.
procedure WriteStr(XPos, YPos, Attribute: Byte; Str: String); assembler; [public, alias: 'SR_WRITESTR'];
asm
???XOR???EDX, EDX?????????{Clear}
???MOV???DX, XPos?????????{XPos}
???MOV???CX, YPos?????????{YPos}
???MOV???ESI, Str?????????{Str pointer}
???SHL???CX, 40?????????{YPos * 80}
???ADD???DX, CX?????????{XPos + (YPos * 80)}
???SHL???DX, 1????????????{DX * 2, because of the attribute}
???ADD???EDX, $B8000?????????{Screen pointer}
???MOV???EDI, EDX?????????{Destination pointer}
???XOR???EAX, EAX?????????{Clear}
???LODSB???????????????{Read string length}
???MOV???ECX, EAX?????????{Set length in counter}
???MOV???AH, Attribute??????{Attribute / Color}
???@PrintChar:
??????LODSB????????????{Put char in AL}
??????STOSW????????????{Write AX to Mem}
???LOOP???@PrintChar?????????{If ECX != 0, write next}
end;
The string is printed on the screen but not at the right place!
SHL???CX, 40 <- PROBLEM
Why is this rong or doesn't work ??? , one shift to left = *2 right?
EDIT: Can it be because i use the ECX (CX) register?
So i wrote a Print Pascal String function...
Because pascal is buildup like this:
db Length, Text, db 0
and when using dynamic strings the compiler does this:
db 2, 'Hi000 .... to 255 ', db 0
So the only chose is to write a print function to deal with this.
procedure WriteStr(XPos, YPos, Attribute: Byte; Str: String); assembler; [public, alias: 'SR_WRITESTR'];
asm
???XOR???EDX, EDX?????????{Clear}
???MOV???DX, XPos?????????{XPos}
???MOV???CX, YPos?????????{YPos}
???MOV???ESI, Str?????????{Str pointer}
???SHL???CX, 40?????????{YPos * 80}
???ADD???DX, CX?????????{XPos + (YPos * 80)}
???SHL???DX, 1????????????{DX * 2, because of the attribute}
???ADD???EDX, $B8000?????????{Screen pointer}
???MOV???EDI, EDX?????????{Destination pointer}
???XOR???EAX, EAX?????????{Clear}
???LODSB???????????????{Read string length}
???MOV???ECX, EAX?????????{Set length in counter}
???MOV???AH, Attribute??????{Attribute / Color}
???@PrintChar:
??????LODSB????????????{Put char in AL}
??????STOSW????????????{Write AX to Mem}
???LOOP???@PrintChar?????????{If ECX != 0, write next}
end;
The string is printed on the screen but not at the right place!
SHL???CX, 40 <- PROBLEM
Why is this rong or doesn't work ??? , one shift to left = *2 right?
EDIT: Can it be because i use the ECX (CX) register?