Please convert this code into assembly code which would work on GUI turbo assemb
ID: 2246441 • Letter: P
Question
Please convert this code into assembly code which would work on GUI turbo assembler.
#include <stdio.h>
#include <conio.h>
void dec_hex(long int num);
void decimalToBinary(long n);
void decimalToRoman(int e);
int main() {
long decimal;
printf("Enter a number from 0 to 999:");
scanf("%ld", &decimal);
decimalToBinary(decimal);
dec_hex(decimal);
decimalToRoman(decimal);
getch();
return 0;
}
/* Function to convert a decinal number to binary number */
void decimalToBinary(long n) {
int remainder;
long binary = 0, i = 1;
while(n != 0) {
remainder = n%2;
n = n/2;
binary= binary + (remainder*i);
i = i*10;
}
printf("Binary number is: %ld ", binary);
}
// Function Definition of decimal to hex
void dec_hex(long int num)
{
long int rem[50],i=0,length=0;
while(num>0)
{
rem[i]=num%16;
num=num/16;
i++;
length++;
}
printf("Hexadecimal number : ");
for(i=length-1;i>=0;i--)
{
switch(rem[i])
{
case 10:
printf("A");
break;
case 11:
printf("B");
break;
case 12:
printf("C");
break;
case 13:
printf("D");
break;
case 14:
printf("E");
break;
case 15:
printf("F");
break;
default :
printf("%ld",rem[i]);
}
}
printf(" ");
}
//Function defenition for roman
void decimalToRoman(int e)
{
int a,b,c;
a = ((e/100)%10)*100;
b = ((e/10)%10)*10;
c = ((e/1)%10)*1;
printf(" ROman number is:");
if (a == 100)
printf("C");
else if (a == 200)
printf("CC");
else if (a == 300)
printf("CCC");
else if (a == 400)
printf("CD");
else if (a ==500)
printf("D");
else if (a == 600)
printf("DC");
else if (a == 700)
printf("DCC");
else if (a ==800)
printf("DCCC");
else if (a == 900)
printf("CM");
if (b == 10)
printf("X");
else if (b == 20)
printf("XX");
else if (b == 30)
printf("XXX");
else if (b == 40)
printf("XL");
else if (b ==50)
printf("L");
else if (b == 60)
printf("LX");
else if (b == 70)
printf("LXX");
else if (b ==80)
printf("LXXX");
else if (b == 90)
printf("XC");
if (c == 1)
printf("I");
else if (c == 2)
printf("II");
else if (c == 3)
printf("III");
else if (c == 4)
printf("IV");
else if (c ==5)
printf("V");
else if (c == 6)
printf("VI");
else if (c == 7)
printf("VII");
else if (c ==8)
printf("VIII");
else if (c == 9)
printf("IX");
}
Explanation / Answer
.MODEL small
.STACK 100h
.DATA
HelloMessage DB 'Hello, world',13,10,'$'
.CODE
.startup
mov ax,@data
mov ds,ax ;set DS to point to the data segment
mov ah,9 ;DOS print string function
mov dx,OFFSET HelloMessage ;point to "Hello, world"
int 21h ;display "Hello, world"
mov ah,4ch ;DOS terminate program function
int 21h ;terminate the program
END
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.