Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PROGRAM 3 : Binary Output Write an HLA Assembly program that prompts for an int 8 value to inspect and then prints it in binary

PROGRAM 3: Binary Output
Write an HLA Assembly program that prompts for an int8 value to inspect and then prints it in binary format. For example, here would be the program output for various entered values
Gimme a decimal value to print: 15
15 is 0000_1111
Gimme a decimal value to print: 7
7 is 0000_0111
(Hint: There is no standard output that prints in binary output, so you need to do this yourself. In order to accomplish this, you need to move a bit at time into the carry flag and print 0 or 1, depending on what you find in the Carry bit. Shift and repeat this procedure 8 times and you are done! Eventually, we will learn how to loop, which would make this task much less terrible.)
(Second Hint: LAHF pushes the Carry Bit and some of the other flags out of the EFLAGS register and into AH. As an Assembly programmer, you have the power to mask out all the bits but the one you are interested in by using either AND or OR.)
Withoug using high level programming such as loops and if statements.
Here is my c code that works but want to convert to HLA assembly
#include
#include
// Function to print a number in binary format
void printBinary(int8_t value){
// Start with the most significant bit (bit 7)
for (int i =7; i >=0; --i){
// Check if the current bit is set (1) or not (0)
if (value & (1<< i))
printf("1");
else
printf("0");
// Add underscore for readability, every 4 bits
if (i %4==0 && i !=0)
printf("_");
}
printf("
");
}
int main(){
int8_t decimalValue;
// Prompt user for input
printf("Gimme a decimal value to print: ");
scanf("%hhd", &decimalValue);
// Print the decimal value and its binary representation
printf("%d is ", decimalValue);
printBinary(decimalValue);
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions