The irresistable source.

Lab 1

1. Description: This is a program written in HLA to convert 32bit decimal numbers into Roman numerals. The program terminates if the user enters 0 for a number.

2. Code

//Program to convert 32bit Decimal number to Roman Numeral.
//Author: Jason Warren
//Date: 10/03/13

program lab1;

#include( "stdlib.hhf" );

begin lab1;

repeat

	stdout.put("Enter a number to convert: ");
	stdin.getu32();

	//Copy user's input to D register.
	mov(eax, edx);

	while( eax > 0 ) do
		if(eax >= 1000) then
			stdout.put("M");
			sub(1000, eax);

		//if result is between 500(inclusive) and 1k(exclusive)
		elseif(eax >= 500) then
			if(eax >= 900) then
				stdout.put("CM");
				sub(900,eax);
			else
				stdout.put("D");
				sub(500, eax);
			endif;

		//if result is between 100(inc) and 500(exclusive)
		elseif(eax >= 100) then
			if(eax >= 400) then
				stdout.put("CD");
				sub(400, eax);
			else
				stdout.put("C");
				sub(100, eax);
			endif;

		//if result is between 50(inclusive) and 100(exclusive)
		elseif(eax >=50) then
			if(eax >= 90) then
				stdout.put("XC");
				sub(90, eax);
			else
				stdout.put("L");
				sub(50, eax);
			endif;

		//if result is between 10(inclusive) and 50(exclusive)
		elseif(eax >= 10) then
			if(eax >= 40) then
				stdout.put("XL");
				sub(40, eax);
			else
				stdout.put("X");
				sub(10, eax);
			endif;

		//if result is between 5(inclusive) and 10(exclusive).
		elseif(eax >=5) then
			if(eax = 9) then
				stdout.put("IX");
				sub(9, eax);
			else
				stdout.put("V");
				sub(5, eax);
			endif;

		else
			if(eax == 4) then
				stdout.put("IV");
				sub(4, eax);

			else
				stdout.put("I");
				sub(1, eax);
			endif;

		endif;	
	endwhile;

stdout.put(nl);
until(edx == 0);

end lab1;

3.lab1(crop) Screenshot

Leave a Reply

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