Lab Description:
In this lab, I had to create a calculator that can add, subtract, and multiply using hla but I couldn’t use any if, while, for, and any related commands. I had to create those commands by using labels, and both conditional, unconditional Jump statement. I also couldn’t use the mul command to multiply. I created a “for” loop to add the input like for example (2*3=6 will be 2+2+2=6) to do the multiplication without the mul command.
Code:
program calc; #include("stdlib.hhf"); static input1: int32; input2: int32; output: int32; input: int32; begin calc; stdout.put("********WELCOME**TO**HLA**CALCULATOR********", nl); labelrepeat: mov(0,eax); mov(0,ebx); mov(0,output); stdout.put("Enter your first input?", nl); stdin.get(input1); stdout.put("Enter your second input?:"); stdin.get(input2); stdout.put("input 1 for add",nl,"input 2 for subtract",nl, "input 3 for multiplication", nl, "input 0 to exit", nl); stdin.get(input); // Assembly code ADD mov(input1, eax); mov(input2, ebx); cmp(input,1); jne Skipstaments; add(eax,ebx); mov(ebx, output); stdout.put("ADD=", output, nl); Skipstaments: // Assembly code SUB mov(input1, eax); mov(input2, ebx); cmp(input, 2); jne Skipstamentss; sub(ebx, eax); mov(eax, output); stdout.put("SUB=",output,nl); Skipstamentss: //Assembly code Multiply without the use of mul mov(input1, eax); mov(input2, ebx); mov(0,ecx); cmp(input, 3); jne Skipstamentsss; //for loop forstmt: cmp(ecx, ebx); jnl forend; inc(ecx); add(eax, output); jmp forstmt; forend: stdout.put("Mul=",output,nl); Skipstamentsss: cmp(input,0); jne labelrepeat; end calc;
Screenshots:
ADD & SUBTRACT:
MULTIPLY: