output function error again

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

output function error again

Post 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
iammisc
Member
Member
Posts: 269
Joined: Thu Nov 09, 2006 6:23 pm

Post 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?
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Post 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
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

Maybe, don't use eax for the video address?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Post by suthers »

sorry stupid question repaired that my self.
Thanks,

Jules
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Post 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
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post 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/
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: output function error again

Post 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
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post 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
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Post by 01000101 »

That was indeed a very good read. Thank you AJ. I'm deffinately putting that in my useful documents folder.
Post Reply