16 Bit Assembly (NASM) Looping issues

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
ajtgarber
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 97
Joined: Wed Jun 10, 2009 8:56 am

16 Bit Assembly (NASM) Looping issues

Post 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.
Firzen
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 23
Joined: Mon Jul 20, 2009 7:13 pm
Current Project: Space Game
Favorite Gaming Platforms: PC, Gamecube, Pandora
Programming Language of Choice: C,C++,C#

Re: 16 Bit Assembly (NASM) Looping issues

Post 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
ajtgarber
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 97
Joined: Wed Jun 10, 2009 8:56 am

Re: 16 Bit Assembly (NASM) Looping issues

Post 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
Firzen
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 23
Joined: Mon Jul 20, 2009 7:13 pm
Current Project: Space Game
Favorite Gaming Platforms: PC, Gamecube, Pandora
Programming Language of Choice: C,C++,C#

Re: 16 Bit Assembly (NASM) Looping issues

Post 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]
ajtgarber
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 97
Joined: Wed Jun 10, 2009 8:56 am

Re: 16 Bit Assembly (NASM) Looping issues

Post 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.
Firzen
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 23
Joined: Mon Jul 20, 2009 7:13 pm
Current Project: Space Game
Favorite Gaming Platforms: PC, Gamecube, Pandora
Programming Language of Choice: C,C++,C#

Re: 16 Bit Assembly (NASM) Looping issues

Post 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.
ajtgarber
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 97
Joined: Wed Jun 10, 2009 8:56 am

Re: 16 Bit Assembly (NASM) Looping issues

Post 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.
Firzen
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 23
Joined: Mon Jul 20, 2009 7:13 pm
Current Project: Space Game
Favorite Gaming Platforms: PC, Gamecube, Pandora
Programming Language of Choice: C,C++,C#

Re: 16 Bit Assembly (NASM) Looping issues

Post 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.
Firzen
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 23
Joined: Mon Jul 20, 2009 7:13 pm
Current Project: Space Game
Favorite Gaming Platforms: PC, Gamecube, Pandora
Programming Language of Choice: C,C++,C#

Re: 16 Bit Assembly (NASM) Looping issues

Post 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
Post Reply