Question: 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 : Binary Output
Write an HLA Assembly program that prompts for an int 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:
is
Gimme a decimal value to print:
is
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 or depending on what you find in the Carry bit. Shift and repeat this procedure 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 printBinaryintt value
Start with the most significant bit bit
for int i ; i ; i
Check if the current bit is set or not
if value & i
printf;
else
printf;
Add underscore for readability, every bits
if i && i
printf;
printf
;
int main
intt decimalValue;
Prompt user for input
printfGimme a decimal value to print: ;
scanfhhd &decimalValue;
Print the decimal value and its binary representation
printfd is decimalValue;
printBinarydecimalValue;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
