Page 1 of 1

output function error again

Posted: Sun Feb 10, 2008 1:33 pm
by suthers
Can anybody see why this output function doesnt work?:

Code: Select all

PutStr_32:
	mov eax, [screen_pos] 	
	.nextchar	
 	lodsb		
 	or al,al	
 	jz .return	
	mov byte [ds:eax], al
	inc eax
	mov byte [ds:eax], 1Bh
 	jmp .nextchar	
	.return
	mov [screen_pos], eax
	ret
        ;data
        screen_pos dd 0B8000h
It loads characters from the si reg into the al and outputs them.
But it just rights random characters at random positions on my screen.
Anybody know why?
Thanks in advance,

Jules

Posted: Sun Feb 10, 2008 1:48 pm
by iammisc
I might be wrong but if you increment eax after setting al, won't al get overwritten because it is the lowest eight bits of eax?

Posted: Sun Feb 10, 2008 4:07 pm
by suthers
What registry could i use as an alternative to al
e.g. I would lodsb before loading anything into eax and then copy it to another registry. then use eax to store the video adress.
Thanks in advance,

Jules

Posted: Sun Feb 10, 2008 4:12 pm
by Combuster
Maybe, don't use eax for the video address?

Posted: Sun Feb 10, 2008 4:12 pm
by suthers
sorry stupid question repaired that my self.
Thanks,

Jules

Posted: Sun Feb 10, 2008 4:15 pm
by suthers
Ok, actually that didnt work i replaced all mentions of eax by ebx but it still didnt work (just printed a random character again, though not the same as before), any ideas why (sorry i should really improve my assembly)
Thanks in advance,

Jules

Posted: Sun Feb 10, 2008 4:26 pm
by Brynet-Inc
I was going to keep quiet, but I decided against it.. ;)

For one, They're called "registers".. not "registries".. :roll:

AL/AH/AX/EAX are the same register..

Example, AL/AH represent the lower/higher 8 bits of AX, and EAX extended AX to 32bits..

Both Intel and AMD distribute x86 documentation:
http://www.amd.com/us-en/Processors/Tec ... 39,00.html
http://www.intel.com/products/processor/manuals/

Re: output function error again

Posted: Tue Feb 12, 2008 3:44 am
by jal
suthers wrote:Can anybody see why this output function doesnt work?:
It would indeed be a good idea to learn how to program in x86 assembly before actually trying to make a working function, as others have mentioned. As you have already noticed you are using eax for the screen position, which is wrong. Some other comments:

Code: Select all

mov eax, [screen_pos]
Since you are writing to the screen (i.e. it is the destination), I'd advise using the edi register (instead of e.g. ebx).

Code: Select all

lodsb
This instruction loads a byte from ds:[esi], then increments esi by 1. I can't see you setting esi anywhere, so I assume you set esi before calling this function? Check its value, most likely it's bogus, causing the random characters to display.

Code: Select all

mov byte [ds:eax], al
A mov instruction by default already uses the ds segment, so no need to specify it. Alternatively, if you set up ds and es the same (which I'd do in protected mode), you could use the stosb instructing if you are using edi as I suggested.

Code: Select all

mov byte [ds:eax], 1Bh
If using the stosb instruction as I suggested above, this would then read 'mov al, 1bh', 'stosb'.

I see you don't check for an overflow of screen_pos, so be prepared that after writing 80x25 characters, you're writing off-screen.


JAL

Posted: Tue Feb 12, 2008 3:55 am
by AJ
Hi,

On the 'choosing the correct register' theme, you may find this source makes quite good reading - it certainly helped me early on in my assembly programming.

Cheers,
Adam

Posted: Tue Feb 12, 2008 4:09 am
by 01000101
That was indeed a very good read. Thank you AJ. I'm deffinately putting that in my useful documents folder.