Hello, I need help translating my code into assembly x86 AT&T Syntax, and not us
ID: 3835884 • Letter: H
Question
Hello, I need help translating my code into assembly x86 AT&T Syntax, and not using the -s to compile it into a .s file.
I need 'a' to be a label with 4 bytes of space, and 'b' to be a label with 4 bytes of space.
Also, place the upper 32 bits of the product into EDX
and the lower 32 bits of the product into EAX
Thank you!
This is my code:
#include <stdio.h>
#include <stdlib.h>
long long mult(long long a, long long b) {
long long ret = 0;
while (b) {
if (b & 1) ret += a;
a <<= 1;
b >>= 1;
}
return ret;
}
int main(int argc, char *argv[]) {
unsigned int a = 0;
unsigned int b = 0;
sscanf(argv[1], "%u", &a);
sscanf(argv[2], "%u", &b);
printf("%u * %u = %llu ", a, b, mult(a, b));
}
Explanation / Answer
try in assembler compiler to execute the code
#include <stdio.h>
#include <stdlib.h>
long long mult(long long a, long long b) {
long long ret = 0;
while (b) {
if (b & 1) ret += a;
a <<= 1;
b >>= 1;
}
return ret;
}
int main(int argc, char *argv[]) {
unsigned int a = 0;
unsigned int b = 0;
sscanf(argv[1], "%u", &a);
sscanf(argv[2], "%u", &b);
printf("%u * %u = %llu ", a, b, mult(a, b));
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.