CET 3510

Lab 1 Description:
The first lab that I had to do was to write a program in HLA that asks the end user to enter a decimal, so that the program could convert the Decimal to Roman and displays the results. The program should continue to ask for decimal numbers until the end user enters zero (0) to exit. When I started this lab, I tried to complicate things by looking at strings and case and using numbers equivalent to letters, but than I realize that all I need was one input, and use the loops like “if” and repeat to complete this lab. I used the repeat loop to end the program when the user enters 0. I used the if loop to convert the decimal to Roman by using the registers to store my input, and than subtract the input and display the letter according to the input. This lab was difficult but at the end I am glad that I did it because it was a good learning experience, and i learned that in assembly language the add and sub is not as simple as in C++, C#, or java.

Code:
program Lab1;
    #include("stdlib.hhf")

static
    input: int32;
    help:  int32;

 begin Lab1;
repeat
    stdout.put("*******DECIMAL*TO*ROMAN*CONVERSION******", nl);    
    stdout.put("Enter a Decimal number from (1-3999): ");
    stdin.get(input);
    if(input>3999 && input<0) then
    stdout.put("Invalid commnad", nl);
    endif;
    stdout.put("Enter 0 to exit",nl);
    mov(input, EAX);
    if(EAX0) then
            stdout.put("The number ",input," is equivalent to : ");
            if(EAX>=1000 && EAX<4000) then                       while(EAX>=1000) do
                  sub(1000, EAX);
                  stdout.put("M");
                  endwhile;
            endif;
            if(EAX>=900) then
                      sub(900, EAX);
                      stdout.put("CM");
            endif;
    if(EAX>=500) then
        sub(500, EAX);
        stdout.put("D");
    endif;
    if(EAX>=400) then
        sub(400,EAX);
        stdout.put("CD");
    endif;
    if(EAX>=100 && EAX<400) then         while(EAX>=100) do

        sub(100, EAX);
            stdout.put("C");
        endwhile;
    endif;
    if(EAX>=90) then
        sub(90, EAX);
        stdout.put("XC");
    endif;
    if(EAX>=50) then
        sub(50, EAX);
        stdout.put("L");
    endif;
    if(EAX>=40) then
        sub(40,EAX);
        stdout.put("XL");
    endif;
        if(EAX>=10 && EAX<40) then         while(EAX>=10) do
            sub(10, EAX);
            stdout.put("X");
        endwhile;
    endif;
    if(EAX>=9) then
        sub(9, EAX);
        stdout.put("IX");
    endif;
    if(EAX>=5) then
        sub(5, EAX);
        stdout.put("V");
    endif;
    if(EAX>=4) then
        sub(4,EAX);
        stdout.put("IV");
    endif;
    if(EAX>=1 && EAX<4) then         while(EAX>=1) do
            sub(1, EAX);
            stdout.put("I");
        endwhile;
    endif;
    stdout.put(" in Roman numeral"nl);
    endif;

until (input=0);
end Lab1;

Screenshots:

lab report screenshot
Screenshot from 2013-10-06 14:09:46

Leave a Reply