Lab Description:
In this lab experiment we have created HLA(High Level Assembly) program that convert a number to roman numeralsĀ that consists of I=1,V=5,X=10,C=100,D=500,M=1000. For example if user entered number 15 which this program will convert roman numerals XV. To execute hla program on linux terminal enter command hla ProgramName.hla and then following command ./ProgramName.
HLA program use these following steps:
-Program ProgramName;
-Static
-begin ProgramName;
-end ProgramName;
Code:
program LabOne; #include("stdlib.hhf") static num: int32; begin LabOne; stdout.put("Please enter a number between 1 and 4000: "); stdin.get(num); mov(num, eax); if(eax<4000 && eax>0) then stdout.put("Roman numeral for ",num," is : "); 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; endif; stdout.put(nl); end LabOne;
Screenshots: