I’m very new in x86 Assembly Language. I’m reading a book called pcasm and I was wondering if someone can help me to understand this code example better (It’s partial code from the book):
32 mov ebx, input2
33 mov ecx, $ + 7
34 jmp short get_int
35
36 mov eax, [input1]
64 get_int:
65 call read_int
66 mov [ebx], eax
67 jmp ecx
Now, what I understand is $ gives the current address, but:
- Why
+ 7? - How can I calculate it?
- What would happen to the number if I use
jmp near get_int(4 bytes) andjmp near word get_int(2 bytes)? Is the second syntax correct or it should bejmp word get_int?
Thanks
The example code uses
+ 7because presumably there are 7 bytes of machine code generated for source lines 33 and 34 combined.You can calculate the offset needed by looking at the assembler output listing (which is something you might have to turn on in your assembler) and counting the bytes.
If you use instructions that assemble to a different number of machine code bytes, then the required offset will be different. You’d have to try it in your environment to see what you need.