Roman Numerals

Introduction:

The Objective of this experiment is to create a program in HLA that asks the user for a number and converts it into Roman Numerals and displays the result.  The program should continue asking the user for more numbers until the user enters zero (0) to exit.Using the basic HLA commands such as while loops and if loops, I was able to construct this program.  After a number  is entered the program will place the number into a 32bit register.  By placing the If loop inside of a while loop, the If loop will repeat as many times as needed picking out the correct Roman Numeral for each repetition until the value of the Decimal number goes to 0.  Then the program will prompt for another number or to enter 0 to exit.

Lab Code

program lab2;
#include ("stdlib.hhf");
static 
rom:int32;

begin lab2;

stdout.put(" Please enter a Number between 1 and 7000",nl);
stdout.put(" The number you enter is going to be converted into Roman numeral ",nl );
 stdin.get(rom);
mov(rom,eax);
while(eax>0)do
    while(eax>0)do

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

    elseif(eax>=999)then
    stdout.put("IM");
     sub(999,eax);

    elseif(eax>=990)then
    stdout.put("XM");
    sub(990,eax);

    elseif(eax>=900)then
    stdout.put("CM");
    sub(900,eax);

    elseif(eax>=500)then
     stdout.put("D");
    sub(500,eax);

    elseif(eax>=499)then
    stdout.put("ID");
    sub(499,eax);

    elseif(eax>=490)then
    stdout.put("XD");
    sub(490,eax);

    elseif(eax>=400)then
    stdout.put("CD");
    sub(400,eax);

    elseif(eax>=100)then
    stdout.put("C");
    sub(100,eax);

    elseif(eax>=99)then
    stdout.put("IC");
     sub(99,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(40,eax);

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

    elseif(eax>=9)then
    stdout.put("IX");
    sub(9,eax);

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

    elseif(eax>=4)then
    stdout.put("IV");
    sub(4,eax);

    elseif(eax>=1)then
    stdout.put("I");
     sub(1,eax);

    endif;
    endwhile;

  stdout.put(nl," Enter another number to be coverted to Roman Numeral if not then enter ");
  mov(0,rom);
  stdin.get(rom);
  Mov(rom,eax);
 endwhile;

end lab2;

 

lab2

Leave a Reply

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