Best way to simulate a call using jmp (dos build)

I use flat assembler on windows and have already modeled a jmp call statement, but wondered if there is a better way to do this with less code? (not using a call)

here is the code.

org 100h mov al, 'x' push come_back ; - simulated "call" - jmp test_label ; - continued - come_back: ; - end of simulated "call" - mov al, 'y' push come_back2 ; - simulated "call" - jmp test_label ; - continued - come_back2: ; - end of simulated "call" - Looop: jmp Looop test_label: mov ah, 0x0e int 0x10 pop cx ; - simulated "ret" - jmp cx ; - end of simulated "ret" 

This code simply displays "xy", two char on the console.

I do not want to use the call because I do not understand the best, and sometimes this is due to the wrong act. I am new to assembly and don't know how best to do this.

+1
assembly dos fasm
source share
2 answers

This might work:

 push $+5 jmp fn ; no label needed here 

Some collectors interpret $ as the address of the instruction.

This is an infinite loop:

 jmp $ 
0
source share

You do it the same way the internal processor does. You must use call and ret to do this. Each instruction takes time to complete. This is called a loop. The more instructions you have, the more cycles it takes, so it takes more time to complete.

Inside, when the processor arrives at the call instruction in your code, this happens:

  • The processor pops the IP register address after your call statement onto the stack.
  • The processor changes the address of the IP register to the address of your call code.
  • Execution in progress.

When the processor arrives at the ret statement in your code, this happens:

  • The processor pops the 16-bit address from the stack and places it in the IP register.
  • Fulfillment of Resume

Although it looks like many steps, these steps take place without power cycles because they are built into the processor hardware.

+2
source share

All Articles