Page 1 of 1

16 Bit Assembly (NASM) Looping issues

Posted: Fri Feb 25, 2011 1:10 pm
by ajtgarber
http://pastebin.com/bhE88WRH

the three instructions that are labeled all give me the same message when I try to assemble this program:
error: operation size not specified
I'm don't know what I need to change.

Just as a note I did check Google, haven't been able to find anything.

Re: 16 Bit Assembly (NASM) Looping issues

Posted: Fri Feb 25, 2011 3:37 pm
by Firzen
http://www.google.com/search?client=ubu ... 8&oe=utf-8

Then the first hit tells you:
you need to use a size specifier so the assembler knows what size your source operand is:
mov dword [testing], 5

Re: 16 Bit Assembly (NASM) Looping issues

Posted: Fri Feb 25, 2011 3:49 pm
by ajtgarber
I've changed it to:

Code: Select all

mov db [Counter], 5
and now its telling me
error: comma, colon or end of line expected

Re: 16 Bit Assembly (NASM) Looping issues

Posted: Fri Feb 25, 2011 3:59 pm
by Firzen
It seems that only word and dword are supported tokens there and db is not.

[edit] Sorry if my help is not that great on nasm, I only use asm on embedded platforms recently and there you specify the size you operate with anyway[/edit]

Re: 16 Bit Assembly (NASM) Looping issues

Posted: Fri Feb 25, 2011 4:35 pm
by ajtgarber
Thanks :), I'm still getting used to NASM and assembly in general, so I'm probably going to end up asking some really stupid questions...

(This probably isn't the place to be asking this but I'll give it a shot)
This little fail of a program is interacting with the BIOS in Real Mode so I'm not sure if I'm messing up any registers that would make the characters
mess up or what I'm doing.

With the normal readKey function (?) it seems to read them in fine, but with the readKeys function which is supposed to only add a loop to the mix,
the characters show up but also some other strange characters come with them.

Re: 16 Bit Assembly (NASM) Looping issues

Posted: Fri Feb 25, 2011 6:07 pm
by Firzen
Well, I see that you wrote a bootloader there, the 0x7C00 and the 0xAA55 kind of give it away. ^^

In general I would recommend to write "Real Mode Assembly" instead of 16 Bit Assembly, because those have a different implication immo.

Anyways, regarding your code there are a few things I'd like to point out.

First you might want to reset the CPU instead of putting it into halt state. To do that simply jump to the 0xAA55 part.
Also I am not sure about the jumping convention on x86, but you might want to use unique label names.

And the issue you asked about with the strange characters happens because in your memory there is only one byte for your buffer. But you seem to be reading 5, so what I think happens is, that your printk function walks past the Buffer byte and prints the Counter one as well, since Counter is not zero when you are printing. So you might want to change your buffers size to something bigger and append 0 to your buffer, you could just do this:

Code: Select all

main:
mov [Counter], 5
mov [Buffer+1], 0
call readKeys
[...]
Prompt db '> ', 0
Buffer resb 2
Counter resb 1
That should resolve your issue with strange characters.

Re: 16 Bit Assembly (NASM) Looping issues

Posted: Sat Feb 26, 2011 1:47 pm
by ajtgarber
I thought real mode assembly was 16 bit? I don't know I'm still getting used to this :P

I never thought about it jumping past the buffer byte, I'll need to try that.

Re: 16 Bit Assembly (NASM) Looping issues

Posted: Sat Feb 26, 2011 2:51 pm
by Firzen
Well, what lodsb does is load a byte from memory and put it into the al register. So if you only check wether al is zero then obviously you step past your buffer.
I mean in asm exactly what you programmed happens. There is no hidden layer or anything, you just need to understand memory adressing and learn the instruction set then you are good to go. At least as long as you do not interface with other hardware.

Re: 16 Bit Assembly (NASM) Looping issues

Posted: Mon Feb 28, 2011 2:33 pm
by Firzen
Oh I just remembered.

In real mode you kind of use 16 bit assembly, but you can use 32 bit adressing mode in asm. In "real" 16 bit programming that's of course not possible.
So the topic implied that you had some issue with adressing in 16-bit mode. And I have to admit that I am not competent regarding that.
Real mode kind of implies "pure asm" and 16-bit implies "16-bit adressing" to me, since that#s the only real difference between 32 and 16 bit. :lol:

Best regards