Reputation: 51
I'm using a flat assembler on windows and have already simulated a call instruction with jmp but was wondering if there's a better way to do it with less code?(not using a call)
here's 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 just display's "xy", two char's to the console.
I don't want to use a call because i wan't a better understanding, and sometimes that involves doing things the wrong way. I'm new to assembly and didn't know what would be the best way to go about this.
Upvotes: 1
Views: 834
Reputation: 48686
You are doing it the same way the processor internally does it. You should be using call
and ret
to do it though. Each instruction takes time to execute. This is called a cycle. The more instructions you have, the more cycles it takes, thus taking more time to execute.
Internally, when the processor comes to a call
instruction in your code, this happens:
IP
register after your call statement onto the stack.IP
register to the address of your call opcode.When the processor comes to a ret
instruction in your code, this happens:
IP
register.Although it seems like a lot of steps, these steps happen without eating up cycles because it is built into the hardware of the CPU.
Upvotes: 2
Reputation: 3352
This might work:
push $+5
jmp fn
; no label needed here
Some assemblers will interpret $
as the instruction address.
This is an infinite loop:
jmp $
Upvotes: 1