Lab 2

pic1

pic2

pic3

Objective:
The objective of this lab experiment was to create a code that is a basic calculator which outputs the answers in roman numerals.

program Calc2;
#include("stdlib.hhf")
static
    r: int32;
    i: int32;
    j: int32;
    x: int32;
    y: int32;
    z: int32;
begin Calc2;
repeat
        stdout.put(nl);
        stdout.put("Choose Operation:");
        stdout.put(nl);
        stdout.put("  1 = Addition");
        stdout.put(nl);
        stdout.put("  2 = Subtraction");
        stdout.put(nl);
        stdout.put("  3 = Multiplication");
        stdout.put(nl);
        stdout.put("  4 = Power Function");
        stdout.put(nl);
        stdout.put("  5 = EXIT");
        stdout.put(nl);
        stdout.put("Enter Option: ");
        stdin.get(x);
        mov(x,eax);

    if(eax=1) then
        stdout.put("    ADDITION");
        stdout.put(nl);
        stdout.put("Enter first value:");
        stdin.get(y);
        mov(y, eax);
        stdout.put("Enter second value:");
        stdin.get(z);
        mov(z, ebx);
        add(eax, ebx);
        
while(ebx > 0) do
        if(ebx >= 100) then
            stdout.put("C");
            sub(100, ebx);
        elseif(ebx >= 99) then
            stdout.put("IC");
            sub(99, ebx);
        elseif(ebx >= 90) then
            stdout.put("XC");
            sub(90, ebx);
        elseif(ebx >=50) then
            stdout.put("L");
            sub(50, ebx);
        elseif(ebx >= 49) then
            stdout.put("IL");
            sub(49, ebx);
        elseif(ebx >= 40) then
            stdout.put("XC");
            sub(40, ebx);
        elseif(ebx >= 10) then
            stdout.put("X");
            sub(10, ebx);
        elseif(ebx >= 9) then
            stdout.put("IX");
            sub(9, ebx);
        elseif(ebx >=5) then
            stdout.put("V");
            sub(5, ebx);
        elseif(ebx>=4) then
            stdout.put("IV");
            sub(4, ebx);
        elseif(ebx >= 1) then
            stdout.put("I");
            sub(1, ebx);
        mov(ebx, z);
        stdout.put(z, nl);
        endif;
    endwhile;
        

        
        
        
    elseif(eax =2) then
        stdout.put("    SUBTRACTION");
        stdout.put(nl);
        stdout.put("Enter first value:");
        stdin.get(y);
        mov(y, eax);
        stdout.put("Enter second value:");
        stdin.get(z);
        mov(z,ebx);
        sub(ebx, eax);
        

while(eax > 0) do
        if(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 >= 49) then
            stdout.put("IL");
            sub(49, eax);
        elseif(eax >= 40) then
            stdout.put("XC");
            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);
        
        mov(ebx, z);
        stdout.put(z, nl);
        endif;
    endwhile;

        
        

    elseif(eax =3) then
        stdout.put("    Multiplication");
        stdout.put(nl);
        stdout.put("Enter first value:");
        stdin.get(y);
        mov(y, eax);
        stdout.put("Enter second value:");
        stdin.get(z);
        mov(z,ebx);
        mul(ebx, eax);
        mov(eax, ebx);


while(ebx > 0) do
        if(ebx >= 100) then
            stdout.put("C");
            sub(100, ebx);
        elseif(ebx >= 99) then
            stdout.put("IC");
            sub(99, ebx);
        elseif(ebx >= 90) then
            stdout.put("XC");
            sub(90, ebx);
        elseif(ebx >=50) then
            stdout.put("L");
            sub(50, ebx);
        elseif(ebx >= 49) then
            stdout.put("IL");
            sub(49, ebx);
        elseif(ebx >= 40) then
            stdout.put("XC");
            sub(40, ebx);
        elseif(ebx >= 10) then
            stdout.put("X");
            sub(10, ebx);
        elseif(ebx >= 9) then
            stdout.put("IX");
            sub(9, ebx);
        elseif(ebx >=5) then
            stdout.put("V");
            sub(5, ebx);
        elseif(ebx>=4) then
            stdout.put("IV");
            sub(4, ebx);
        elseif(ebx >= 1) then
            stdout.put("I");
            sub(1, ebx);
        mov(ebx, z);
        stdout.put(z, nl);
        endif;
    endwhile;


    elseif(eax =4) then
        stdout.put("    POWER");
        stdout.put(nl);
        stdout.put("Enter first value:");
        stdin.get(y);
        mov(y, eax);
        stdout.put("Enter power value:");
        stdin.get(z);
        mov(z,ebx);
        mov(1,r);
        for(mov(0,i); i<ebx; inc (i)) do
            mov(0,ecx);
                for(mov(0,j);j 0) do
        if(ebx >= 100) then
            stdout.put("C");
            sub(100, ebx);
        elseif(ebx >= 99) then
            stdout.put("IC");
            sub(99, ebx);
        elseif(ebx >= 90) then
            stdout.put("XC");
            sub(90, ebx);
        elseif(ebx >=50) then
            stdout.put("L");
            sub(50, ebx);
        elseif(ebx >= 49) then
            stdout.put("IL");
            sub(49, ebx);
        elseif(ebx >= 40) then
            stdout.put("XC");
            sub(40, ebx);
        elseif(ebx >= 10) then
            stdout.put("X");
            sub(10, ebx);
        elseif(ebx >= 9) then
            stdout.put("IX");
            sub(9, ebx);
        elseif(ebx >=5) then
            stdout.put("V");
            sub(5, ebx);
        elseif(ebx>=4) then
            stdout.put("IV");
            sub(4, ebx);
        elseif(ebx >= 1) then
            stdout.put("I");
            sub(1, ebx);
        mov(ebx, z);
        stdout.put(z, nl);
        endif;
    endwhile;
    
        
    endif;
until(eax =5);

end Calc2;

Leave a Reply

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