My NASM problem

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
K.J.

My NASM problem

Post 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.
f2

Re:My NASM problem

Post by f2 »

What lines do these warnings/errors point to? I think I have an idea what's wrong.
Dave_Hunt

Re:My NASM problem

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

Re:My NASM problem

Post 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.
Dave_Hunt

Re:My NASM problem

Post 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.
bchadwick01

Re:My NASM problem

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

Re:My NASM problem

Post 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!
K.J.

Re:My NASM problem

Post by K.J. »

Thanks Dave_Hunt and bchadwick01.

I got my code working thanks to your suggestions.

Thanks,
K.J.
Dave_Hunt

Re:My NASM problem

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