`js` and `jb` instructions in assembly
There exists a handy table that does explain very well which Jcc instruction to use: Jump conditions and flags:
There exists a handy table that does explain very well which Jcc instruction to use: Jump conditions and flags:
I hope it’s obvious that phase4 is checking that the first number is in the range 0..14 inclusive (see lines +44..+57) Then it invokes func4 with three arguments: the first number entered, 0 and 14 (lines +62..+85). Next it checks that the return value is 0x25 (37 decimal) on line +90 and that the second … Read more
LEA (load effective address) just computes the address of the operand, it does not actually dereference it. Most of the time, it’s just doing a calculation like a combined multiply-and-add for, say, array indexing. In this case, it’s doing a simple numeric subtraction: leal -4(%ebp), %eax just assigns to the %eax register the value of … Read more
ESP is the current stack pointer. EBP is the base pointer for the current stack frame. When you call a function, typically space is reserved on the stack for local variables. This space is usually referenced via EBP (all local variables and function parameters are a known constant offset from this register for the duration … Read more
If your modulus / divisor is a known constant, and you care about performance, see this and this. A multiplicative inverse is even possible for loop-invariant values that aren’t known until runtime, e.g. see https://libdivide.com/ (But without JIT code-gen, that’s less efficient than hard-coding just the steps necessary for one constant.) Never use div for known powers of 2: it’s much slower than and for remainder, … Read more
These two lines are your problem: eax is 32 bits, but both my1337Sk1LLz and Difference are 16 bits. There are two ways you might get around this: Changing the size of my1337Sk1LLz and Difference. Right now you have the types as WORD and SWORD, respectively. You can change those to DWORD and SDWORD to make … Read more
Brackets in [ESP+18h] mean that the destination of the MOV is memory location at ESP+18h. As an example, if ESP has value 10000000h, then your destination is memory location 10000018h. DWORD defines ‘size’ of the memory location used for move operation. In you example, you’d be moving 0000000Ah (4 bytes) into memory location ESP+18h. As … Read more
Can you please tell me the difference between JUMP IF ABOVE AND JUMP IF GREATER in Assembly language? when do i use each of them? do they give me different results?
The dword ptr part is called a size directive. This page explains them, but it wasn’t possible to direct-link to the correct section. Basically, it means “the size of the target operand is 32 bits”, so this will bitwise-AND the 32-bit value at the address computed by taking the contents of the ebp register and … Read more
Have you tried int 21h service 2? DL is the character to print. To print the integer value, you’ll have to write a loop to decompose the integer to individual characters. If you’re okay with printing the value in hex, this is pretty trivial. If you can’t rely on DOS services, you might also be … Read more