Lab Description:
This lab required us to create a decimal to Roman numeral converting program in HLA. This specific program used one of the simplest methods which is utilizing only subtraction.
Code:
program decimaltoroman; #include("stdlib.hhf") // Yevgeniy Babkin --- CET3510 // // this program provides a simple way to convert // Decimal numbers to Roman numerals static // declare a 16-bit variable thats greater than 0. x: int32:=999; begin decimaltoroman; // console.cls(); clears the original cmd window for a cleaner look. console.cls(); // main while loop that establishes an exit strategy; while((x != 0)&&(x != 4000)) do stdout.put(nl,"Please input a number [1-3999] : "); //the following commands "cin" the user input number // and move it into the 32 bit register stdin.get(x); mov(x, EAX); //next line is the main if loop that see's if the number is within 1-3999 range //prgrm will not run right without it!!! if(EAX<4000 && EAX>0)then //spacing is added to the 1st stdout to center the wording for //easier readability stdout.put(nl " Your number: ",x, nl, " Roman Numeral equivalent: "); //the program is fairly basic as it subtracts known roman numeral values //to figure out which and how many roman numearals to display. 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; // last stdout lets user know how to exit the program // by entering 0, even though a user can enter; either 0 or // a number greater than 3999 and still exit the program // but for simplicity and a cleaner look a 0 is enough. stdout.put(nl, nl, " TO END PROGRAM ENTER [0]",nl); stdout.put(" Otherwise keep converting!!!" ,nl,nl); endif; endwhile; end decimaltoroman;
Screenshot: