Objective:
The objective of this lab experiment was to create a 32 bit program similar to the last experiment that computed addition, subtraction, multiplication, and power functions; however, jumps and labels had to replace any if, while, or for commands.
program Calc3; #include("stdlib.hhf") static a: int32; r: int32; i: int32; j: int32; x: int32; y: int32; z: int32; begin Calc3; LabelMenu: 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,edx); WhileLabel: cmp(edx,1); je Labeladd; jne Labelsubtract; Labeladd: 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); mov(ebx, z); stdout.put(z, nl); jmp LabelMenu; Labelsubtract: cmp(edx,2); jne Labelmultiply; 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); mov(eax,z); stdout.put(z, nl); jmp LabelMenu; Labelmultiply: cmp(edx,3); jne Labelpower; 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); mov(eax,ebx); shl(3,eax); sub(ebx,eax); mov(eax,a); stdout.put(a, nl); jmp LabelMenu; Labelpower: cmp(edx,4); jg WhileDone; 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<eax; inc(j)) do add(r,ecx); endfor; mov(ecx,r); endfor; stdout.put(r, nl); jmp LabelMenu; WhileDone: end Calc3;