`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:
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
A x64 native (AMD64 or Intel 64) processor is only mandated to support SSE and SSE2. SSE3 is supported by Intel Pentium 4 processors (“Prescott”), AMD Athlon 64 (“revision E”), AMD Phenom, and later processors. This means most, but not quite all, x64 capable CPUs should support SSE3. Supplemental SSE3 (SSSE3) is supported by Intel … Read more
A trap is an exception in a user process. It’s caused by division by zero or invalid memory access. It’s also the usual way to invoke a kernel routine (a system call) because those run with a higher priority than user code. Handling is synchronous (so the user code is suspended and continues afterwards). In … Read more
JNZ is short for “Jump if not zero (ZF = 0)”, and NOT “Jump if the ZF is set”. If it’s any easier to remember, consider that JNZ and JNE (jump if not equal) are equivalent. Therefore, when you’re doing cmp al, 47 and the content of AL is equal to 47, the ZF is set, ergo the jump (if Not … Read more
When you do a cmp a,b, the flags are set as if you had calculated a – b. Then the jmp-type instructions check those flags to see if the jump should be made. In other words, the first block of code you have (with my comments added): would jump to label1 if and only if al was greater than dl. You’re probably better … Read more
As has already been stated, wrapping brackets around an operand means that that operand is to be dereferenced, as if it were a pointer in C. In other words, the brackets mean that you are reading a value from (or storing a value into) that memory location, rather than reading that value directly. So, this: … Read more
movq (assuming you’re talking about x86) is a move of a quadword (64-bit value). This particular instruction: looks very much like code that will walk up through stack frames. This particular instruction grabs the quadword pointed to by the current stack pointer, and loads it into the stack pointer, overwriting it. By way of example, this … Read more
RIP addressing is always relative to RIP (64bit Instruction Pointer) register. So it can be use for global variables only. The 0 offset is equal to address of the following instruction after the RIP-addressed instruction. For example: You wouldn’t normally mix data right in with your code, except as an immediate, but this shows what … Read more
As Intel’s manual explains, JG interprets the flags as though the comparison was signed, and JA interprets the flags as though the comparison was unsigned (of course if the operation that set the flags was not a comparison or subtraction, that may not make sense). So yes, they’re different. To be precise, ja jumps if CF = 0 and ZF … Read more