Kat H.

asked • 05/09/21

Write the assembly code in AT&T syntax for digits.c and height.c intended for people to be able to read it, not in assembly compiled and generated by a machine.

Write the assembly code in AT&T syntax for digits.c and height.c intended for people to be able to read it, not in assembly compiled and generated by a machine. They are both in C. Write the assembly code for both as separate assignments.


Code:

digits.c

#include

//Global input variable
int input = 247; // 0<=input<1000

//Global output variable declarations
int ones = 0;
int tens = 0;
int hundreds = 0;

int main(){

int temp = input;
ones = temp%10;
temp /= 10;
tens = temp%10;
temp /= 10;
hundreds = temp;

printf("Input: %d\n",input);
printf("Ones: %d\n",ones);
printf("Tens: %d\n",tens);
printf("Hundreds: %d\n",hundreds);

}

height.c

#include
#include
#define g 9.8

//Global input variable
double velocity = 24.7; // unit: m/s

//Global output variable declarations
double height;

int main(){

//Formula used: height = (1/2) * (((velocity)^2)/g)
height = (1.0/2) * ((pow(velocity,2))/g);

printf("Initial Velocity: %lf m/s\n",velocity);
printf("Height: %lf m\n",height);

}


1 Expert Answer

By:

Sid M.

tutor
Here's height.c: ```# height.c # # #include <stdio.h> # #include <math.h> # #define g 9.8 .extern _pow .extern _printf .data # //Global input variable # double velocity = 24.7; // unit: m/s velocity: .double 24.7 # //Global output variable declarations # double height; height: .double 0.0 g: .double 9.8 half: .double 0.5 # int main(){ .text .global _start: pushl %ebp movl %esp, %esp # //Formula used: height = (1/2) * (((velocity)^2)/g) # height = (1.0/2) * ((pow(velocity,2))/g); pushl $2 pushl velocity + 4 pushl velocity call _pow fld g fdiv fld half fmul fstp height # printf("Initial Velocity: %lf m/s\n", velocity); .data MsgVelocity: .ascii "Initial Velocity: %lf m/s\n", 0 .text pushl velocity + 4 pushl velocity pushl $MsgVelocity call _printf addl $12, %esp # printf("Height: %lf m\n", height); .data MsgHeight: .ascii "Height: %lf m\n", 0 .text pushl height + 4 pushl height pushl $MsgHeight call _printf addl $12, %esp movl %ebp, %esp popl %ebp ret # }```
Report

05/27/21

Sid M.

tutor
Sigh....
Report

05/27/21

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.