LAB 1

LAB DESCRIPTION:

This first lab we had for this class was to write a program to convert decimal numbers to Roman numbers. I have to say it was more than challenging for me. I have never thought of doing a program like that and I’m still new with this new language, it was pretty tough. But with reading and asking question. I was about to finish it. I named the program “Roman”. I decided to use the “if and then” conditions to write this program.

Code:

 

program Roman;
#include( "stdlib.hhf");
static
n:int32;
begin Roman;
stdout.put( "Enter a number: ");
	stdin.get(n);
	mov(n,eax);
	while(eax>0) do
	if(eax>=100)then
		stdout.put("C");
		sub( 100,eax);

		elseif(eax>= 90) then
		stdout.put("XC");
		sub(90,eax);

		elseif(eax>= 50) then
		stdout.put("L");
		sub(50,eax);

		elseif(eax>=40) then
		stdout.put("XL");
		sub(10,eax);

		elseif(eax>=10) then
		stdout.put("x");
		sub(10,eax);

		elseif(eax>=5) then
		stdout.put("V");
		sub(5,eax);

		elseif(eax>=1) then
		stdout.put("I");
		sub(1,eax);
	endif;
	endwhile;
	stdout.put(nl);
end Roman;

Screenshot:

pic2

Leave a Reply

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