YJDoc2 / 8086-emulator-web

Repository for 8086 emulator web implementation
Apache License 2.0
222 stars 26 forks source link

Procedure name issue / Infinite Loop with a CALL #21

Closed SomphonSy closed 2 years ago

SomphonSy commented 2 years ago

Hello , there is some issue with the definition of the procedure and with the interaction with the CALL instruction.

First in your documentation example , it seems like the procedure name can have a - in his name

Used to define procedure, which can be used with CALL instruction
Usage:
def proc-name { procedure body } : Procedure Body can contains opcodes and macro use

But with this code :

def proc-name {
    MOV AX,0x55
}

start:
CALL proc_name
MOV AX,0x56

I have the following error :

Errors:
Syntax Error : Invalid token at 8

And with a correct procedure name like the following code , there is an other problem :

def test_procedure {
    MOV AX,0x55
    RET
}

start:
CALL test_procedure
MOV AX,0x56

The RET instruction (i guess) , is returning the address to the CALL test_procedure instead of the next instruction , creating an infinite loop .

Anyway thanks for your 8086-emulator , it's a nice tools to start learning assembly !

YJDoc2 commented 2 years ago

Hey, Thanks for reporting this! Hope you're finding this useful :)

The - is actually not allowed in the procedure name, but the current documentation can make it seem like it is, sorry for that, I'll change it.

And your guess is correct, the emulator maintains an internal stack for call instruction, and the call pushes current address on the stack, and ret just returns it, so it essentially keeps executing call instruction again and again.

I'll fix it soon, along with another issue that is currently getting fixed. Thanks again for reporting this error :+1:

Anyway thanks for your 8086-emulator , it's a nice tools to start learning assembly !

Happy that it helps :)

YJDoc2 commented 2 years ago

Hey, I have made a patch that should fix this issue, you might need to do a hard refresh (ctrl+f5) on the website in case it still uses cached pages.

I have updated the docs to specify valid proc names, as well as fixed the infinite call looping. Please check once :) Thanks again for reporting the error :smile:

If there is still some error regarding this or issue, comment here, or feel free to close the issue :)