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.
I am trying to add a command table to my os. I can compare the data that was typed into the prompt with the table and determine which command was entered, but I can figure out how to make it call the function.
mov si, commands ;set si to command table
mov di, buffer ;set di to command
mov cx, 0
jmp NewChar
NextCmd:
inc cx
mov di, buffer ;set di to command
NewChar:
lodsb ; AL = [SI]
test al, al ; if [si] = 0 then end of command
jz FoundCmd ; in command table
mov ah, [di] ; load [di]
inc di ; next char in command
or ah, 0x20 ; convert user input to lowercase
cmp al, ah ; compare user to command table
jz NewChar
LoopTo0: ; ok not this command
lodsb ; so now we need to go the end
test al, al ; of command in the command table
jnz LoopTo0 ; marked by 0
cmp byte [si], 0xFF
jne NextCmd ; no? - good, check next command
mov si, badcommand
call print
jmp mainloop
FoundCmd:
;How do i call the function here?
jmp mainloop
I'm not extraordinarily versed in ASM myself, and I usually only use it where absolutely needed. If I were you, I'd make the call_table an array of function pointers.
call_table:
_cmd1 dd 0
_cmd2 dd 0
_cmd3 dd 0
cmd1:
mov eax, 0
ret
cmd2:
mov eax, 1
ret
cmd3:
mov eax, 2
ret
setup_cmd_table:
mov ebx, cmd1
mov _cmd1, ebx
mov ebx, cmd2
mov _cmd2, ebx
mov ebx, cmd3
mov _cmd3, ebx
ret
; In order to call any of the commands, you just access the index in cmd_table, and do like so:
mov ebx, cmd1
call [ebx]
But I'm sure someone more versed (*coughDexcough*) could probably offer something more solid.
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.