lab 1

Lab Description:
In this lab, the program ask the user to input a decimal number, convert it and then display the result in roman numeral, the program should run until the user input zero. The approach I used is as falow: I declared a 32 bit variable name x, moved it to the register eax, and proceed to the printing of the highest roman that can go into the decimal entered, afterward I subtract the equivalent printed value and repeat the process until it reaches zero. I used a while loop in combinasion with if statements to run through all the roman numeral contained in the number that the user input. Keep in mind that C=100, L=50, X=10, V=5, I=1.

Code:

program roman;
#include("stdlib.hhf")
static
	x:int32:=1;
begin roman;
	stdout.put(" ", nl);
	stdout.put("This program will ask the user to input a decimal number, convert it and display the Roman numeral equivalent.",nl);
	stdout.put(" ",nl);
	while(x>0) do
	stdout.put(" ", nl);
	stdout.put("Please enter a decimal number:");
	stdin.get(x);
	mov(x,eax);
	stdout.put("The roman numeral equivalent to ", x , " is: ");
		if(eax>=100) then
			while(eax>=100) do
				sub(100,eax);
				stdout.put("C");
			endwhile;
		endif;
		if (eax>=90) then
			stdout.put("XC");
			sub(90,eax);
		endif;
		if (eax>=50) then 
			stdout.put("L");
			sub(50,eax);
		endif;
		if (eax>=40) then
			stdout.put("XL");
			sub(40,eax);
		endif;
		if(eax>=10) then
			while(eax>=10) do
				sub(10,eax);
				stdout.put("x");
			endwhile;
		endif;
		if (eax>=9) then
			stdout.put("IX");
			sub(9,eax);
		endif;
		if (eax>=5) then 
			stdout.put("V");
			sub(5,eax);
		endif;
		if (eax>=4) then
			stdout.put("IV");
			sub(4,eax);
		endif;
		if(eax>=1) then 
			while(eax>=1) do
				stdout.put("I");
				sub(1,eax);
			endwhile;
		endif;
		stdout.put(nl);
	endwhile;
if (x=0) then
stdout.put("Oops You entered zero, this is not valid good bye.", nl);
endif;
stdout.put(" ", nl);

end roman;

Screenshots:
Screenshot from 2013-10-06 01:52:18 

 

Leave a Reply

Your email address will not be published. Required fields are marked *