Page 1 of 1

My NASM problem

Posted: Sun Apr 07, 2002 11:28 pm
by K.J.
The following NASM code doesn't want to work and I can't figure out why:

[tt][BITS 32]
[SECTION .text]

_kbd_isr:            ; just "kbd_isr" in C
   cli
   mov esi, pKbdRawIn      ;pointer to the raw kbd buffer
   xor eax, eax      ;zero eax
   in al, 60h         ;get 1 byte from the keyboard

   mov ebx, KbdRawCnt   ;check if the raw buffer is full
   cmp ebx, 20h
   je kbd_isr_finish      ;if it is, exit
   mov byte esi, al      ;store al(byte from the kbd) in the raw buffer
   inc dword [KbdRawCnt]
   inc esi
   cmp esi, KbdRawBuf+20h   ;are we past the end of the buffer?
   jb kbd_isr_finish
   mov esi, KbdRawBuf

kbd_isr_finish:
   mov pKbdRawIn, [esi]
   out 0x20, 0x20
   sti
   ret

[SECTION .data]

KbdRawBuf:
   times 32 DB 0   ;32-byte raw buffer

KbdRawCnt:
   DD 0

pKbdRawIn:
   DD KbdRawBuf

pKbdRawOut:
   DD KbdRawBuf


KbdBuffer:
   times 64 DD 0   ;64 DWords for the translated kbd buffer

KbdCnt:
   DD 0

pKbdIn:
   DD KbdBuffer

pKbdOut:
   DD KbdBuffer[/tt]

I compile like this:
[tt]nasm -f aout kbd.asm[/tt]

and get these errors:
kbd.asm:13: warning: register size specification ignored
kbd.asm:13: invalid combination of opcode and operands
kbd.asm:21: invalid combination of opcode and operands
kbd.asm:22: invalid combination of opcode and operands


Thanks in advance,
K.J.

Re:My NASM problem

Posted: Mon Apr 08, 2002 4:07 am
by f2
What lines do these warnings/errors point to? I think I have an idea what's wrong.

Re:My NASM problem

Posted: Mon Apr 08, 2002 8:07 am
by Dave_Hunt
Line 13:

Replace with: mov esi,eax
(you already have the rest of eax zeroed out, so this will work fine.)

Line 21:

Replace with:
mov eax, [esi] (or any other available register)
mov [pKbdRawIn], eax

(mov [pKbdRawIn],[esi] might work)

Line 22:

Replace with:
mov dx,0x20
mov al,0x20
out dx,al

Re:My NASM problem

Posted: Mon Apr 08, 2002 12:23 pm
by f2
>> Replace with: mov esi,eax <<

Why? I don't understand this. I DO understand that the error was because he was trying to go from 4bit to 32bit, but I don't understand why you changed it to this.

Re:My NASM problem

Posted: Mon Apr 08, 2002 12:40 pm
by Dave_Hunt
Tommy wrote: >> Replace with: mov esi,eax <<

Why? I don't understand this. I DO understand that the error was because he was trying to go from 4bit to 32bit, but I don't understand why you changed it to this.
I just realized (by reading his comments) what he was trying to do. It should have been:

mov [esi],al

Silly me.

Re:My NASM problem

Posted: Mon Apr 08, 2002 1:14 pm
by bchadwick01
>Line 22:
>
>Replace with:
> mov dx,0x20
> mov al,0x20
> out dx,al

Just for clarity... this can also be written as:

mov al,0x20
out 0x20,al

as long as the port # fits into one byte

BC

Re:My NASM problem

Posted: Mon Apr 08, 2002 5:27 pm
by f2
Dave_Hunt wrote:
Tommy wrote: >> Replace with: mov esi,eax <<

Why? I don't understand this. I DO understand that the error was because he was trying to go from 4bit to 32bit, but I don't understand why you changed it to this.
I just realized (by reading his comments) what he was trying to do. It should have been:

mov [esi],al

Silly me.
What would you mov the value of register AL into what is at the address of esi? Can you please explain this in some detail? Thanks!

Re:My NASM problem

Posted: Mon Apr 08, 2002 10:34 pm
by K.J.
Thanks Dave_Hunt and bchadwick01.

I got my code working thanks to your suggestions.

Thanks,
K.J.

Re:My NASM problem

Posted: Tue Apr 09, 2002 3:59 pm
by Dave_Hunt
K.J.,

Glad to help!


Tommy,

esi is pointing to his keyboard buffer (pKbdRawIn). So, the "mov [esi],al" would move the byte entered at the keyboard (retrived via "in al,60h") into the buffer.