2 ms·
> The operations C gives you map 1-to-1 with assembly int test(int x, int y) { return x % y; } test: //
by Joker_vD 3y ago
> The operations C gives you map 1-to-1 with assembly
int test(int x, int y) {
return x % y;
}
test: // @test
sdiv w8, w0, w1
msub w0, w8, w1, w0
ret
Surprisingly, assembly doesn't have the remainder instruction, but instead it has a multiply-then-subtract instruction which is not corresponding 1-to-1 to anything in C.
- IshKebab 3y agox86 doesn't have remainder. Other instruction sets do. But yeah I agree with your point. Some targets might not even have multiply.
- Joker_vD 3y agox86 has remainder: IDIV calculates both the quotient and the remainder at the same time and places them in different registers just like many other ISAs before it did. In fact, DIV instruction of PDP-11 worked that way too: Description: The 32-bit two's complement integer in R and Rv1 is divided by the source operand. The quotient is left in R; the remain- der in Rv1. Division will be performed so that the remainder is of the same sign as the dividend. R must be even. Example: CLR RO MOV #20001,R1 DIV #2, RO Before After (RO) = 000000 (RO) = 010000 Quotient (R1) = 020001 (R1) = 000001 Remainder PDP-11 also had ADC and SBC (add/subtract with carry) instructions which weren't (and still aren't) exposed in C either.
- messe 3y ago> x86 doesn't have remainder The code in the comment you replied to is 64-bit ARM assembly.
- IshKebab 3y agoOops of course.