Lab # 2 32 bit calculator with Roman Numerals

This lab is using the 32 bit calculator we did in Lab 1 and expanding it by adding a converting a decimal number to Roman Numeral. We use the same process as 1 addition, 2 substraction, 3 multiplication, 4 exponentiation, 5 convert to roman numerals. The system will display a warning message when a value goes over 65536. The Multiplication must be a loop.

program lab2;
#include( “stdlib.hhf”);
static
n:int32;
n1:int32;
n2:int32;
begin lab2;
stdout.put(“Press [1]:Addition [2]:Subtraction [3]:Multiplication [4]:Exponentiation [5]:Roman numeral [0]:exit”,nl);
repeat
stdout.put(nl);
stdout.put(“Do operation number: or press 0 to exit:”);
stdin.get(n);
mov(n, ecx);
if(n=1) then
stdout.put(“enter n1: “);
stdin.get(n1);
if(n1>65536) then
stdout.put(” overflow”,nl);
endif;
mov(n1, eax);
stdout.put(“enter n2: “);
stdin.get(n2);
if(n2>65536) then
stdout.put(” overflow “,nl);
endif;
mov(n2, ebx);
add(eax, ebx);
mov(ebx,n);
stdout.put(“The sum is:” ,n, nl);
elseif (n=2) then
stdout.put(“enter n1: “);
stdin.get(n1);
if(n1>65536) then
stdout.put(“overflow “,nl);
endif;
mov(n1, ebx);
stdout.put(“enter n2: “);
stdin.get(n2);
if(n2>65536) then
stdout.put(“overflow “,nl);
endif;
mov(n2,eax);
sub(eax,ebx);
mov(ebx,n);
stdout.put(nl);
stdout.put(“The difference is:”,n, nl);
elseif (n=3) then
stdout.put(“enter n1: “);
stdin.get(n1);
if(n1>65536) then
stdout.put(“overflow “,nl);
endif;
mov(n1,eax);
stdout.put(“enter n2: “);
stdin.get(n2);
if(n2>65536) then
stdout.put(“overflow “,nl);
endif;
mov(n2,ebx);
mov(0,eax);
for(mov(0,ecx); ecx65536) then
stdout.put(“overflow “,nl);
endif;
mov(n1,eax);
stdout.put(“enter n2: “);
stdin.get(n2);
if(n2>65536) then
stdout.put(“overflow “,nl);
endif;
mov(n2,ecx);
if(ecx=0)then
mov(1,eax);
else
while(ecx!=1)do
mov(0,ebx);
while(eax!=0)do
add(n1,ebx);
dec(eax);
endwhile;
mov(ebx,eax);
dec(ecx);
endwhile;
endif;
mov(eax,n);
stdout.put(” Answer is:”,n, nl);
elseif (n=5) then
stdout.put(“enter n:”);
stdin.get(n);
mov(n,eax);
stdout.put(“roman is: “);
if(eax>=100) then
while(eax>=100) do
sub(100,eax);
stdout.put(“C”);
endwhile;
endif;
if (eax>=90) then
stdout.put(“XC”);
sub(90,eax);
endif;
if (eax>=50) then
stdout.put(“L”);
sub(50,eax);
endif;
if (eax>=40) then
stdout.put(“XL”);
sub(40,eax);
endif;
if(eax>=10) then
while(eax>=10) do
sub(10,eax);
stdout.put(“X”);
endwhile;
endif;
if (eax>=9) then
stdout.put(“IX”);
sub(9,eax);
endif;
if (eax>=5) then
stdout.put(“V”);
sub(5,eax);
endif;
if (eax>=4) then
stdout.put(“IV”);
sub(4,eax);
endif;
if(eax>=1) then
while(eax>=1) do
stdout.put(“I”);
sub(1,eax);
endwhile;
endif;
endif;
until(n=0);
end lab2;

Screenshot-4

Leave a Reply

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