In assembly language: Boolean Calculator Create a program that functions as a si
ID: 3817321 • Letter: I
Question
In assembly language:
Boolean Calculator
Create a program that functions as a simple Boolean calculator for 32
bit integers. It should display a menu that asks the user to make a
selection from the following list:
1. x AND y
2. x OR y
3. NOT x
4. x XOR y
5. Exit the program
The program should run in a loop. When the user makes a choice, call
a procedure called ChooseProcedure which invokes the appropriate
procedure to perform the logical operation as outlined below:
AND_op : Prompt the user for two hexadecimal integers . AND them
together and displays the result in hexadecimal.
OR_op : Prompt the user for two hexadecimal integers . OR them
together and displays the result in hexadecimal.
NOT_op : Prompt the user for a hexadecimal integer . NOT the integer
and displays the result in hexadecimal.
XOR_op : Prompt the user for two hexadecimal integers . XOR them
together and displays the result in hexadecimal.
Error checking : Your program should check for valid menu selection.
In case of invalid selection, it will do nothing but will continue waiting
for input.
Implement the program with case table
Explanation / Answer
Pleaee find below the BooleanCalculator assembly code using case table: INCLUDE Irvine32.inc .data caseTable byte '1' ;lookup value dword Process_1 ;address of lookup value entrySize = ($ - caseTable ) byte '2' dword Process_2 byte '3' dword Process_3 byte '4' dword Process_4 byte '5' dword Process_5 numberOfEntries = 5 msgIntro byte "This is Your Name's fourth assembly program which will later",0dh,0ah byte "function as a simple boolean calculator for 32-bit integers. The",0dh,0ah byte "current output will only be the name of the operation about to be",0dh,0ah byte "performed as selected by the user.",0dh,0ah,0 msgSelMn byte "-------------------------------------",0dh,0ah byte " 32-Bit Boolean Calculator" ,0dh,0ah byte "-------------------------------------",0dh,0ah byte "1. x AND y" ,0dh,0ah byte "2. x OR y" ,0dh,0ah byte "3. NOT x" ,0dh,0ah byte "4. x XOR y" ,0dh,0ah byte "5. Exit Program",0dh,0ah byte "-------------------------------------",0dh,0ah byte "Please enter selection 1,2,3,4 or 5: ",0 msg1 byte "Calling Process 1 (x AND y)",0dh,0ah,0 msg2 byte "Calling Process 2 (x OR y)",0dh,0ah,0 msg3 byte "Calling Process 3 (NOT x)",0dh,0ah,0 msg4 byte "Calling Process 4 (x XOR y)",0dh,0ah,0 msg5 byte "Calling Process 5 (Exit Program)",0dh,0ah,0 .code main PROC ;///////Intro Message///////////////////////////////// mov edx,OFFSET msgIntro ;intro message into edx call WriteString ;display msgIntro call Crlf ;endl call WaitMsg ;pause message call Clrscr ;clear screen call Menu ;menu procedure ExitProg::exit ;global label to exit main ENDP ;------------------------------------------------ Menu PROC ; ; Receives: Nothing ; Returns: Nothing ;------------------------------------------------ mov edx,OFFSET msgSelMn ;ask user for input call WriteString ;display msgSelMn call ReadChar ;read one character mov ebx,OFFSET caseTable;point EBX to the table mov ecx,numberOfEntries ;loop counter L1: cmp al,[ebx] ;match found? jne L2 ;no: continue call NEAR PTR [ebx + 1] ;yes: call the procedure call WriteString ;display message call Crlf ;endl call WaitMsg ;pause message call Clrscr ;clear screen jmp L3 ;exit the search L2: add ebx,5 ;point to the next entry loop L1 ;repeat until ECX = 0 L3: jmp Menu ;run Menu again Menu EndP ;------------------------------------------------ Process_1 PROC ; ; Receives: Nothing ; Returns: EDX = offset of message ;------------------------------------------------ mov edx,OFFSET msg1 ;msg1 into edx call Crlf ;endl call Crlf ;endl ret ;return Process_1 ENDP ;------------------------------------------------ Process_2 PROC ; ; Receives: Nothing ; Returns: EDX = offset of message ;------------------------------------------------ mov edx,OFFSET msg2 ;msg2 into edx call Crlf ;endl call Crlf ;endl ret ;return Process_2 ENDP ;------------------------------------------------ Process_3 PROC ; ; Receives: Nothing ; Returns: EDX = offset of message ;------------------------------------------------ mov edx,OFFSET msg3 ;msg3 into edx call Crlf ;endl call Crlf ;endl ret ;return Process_3 ENDP ;------------------------------------------------ Process_4 PROC ; ; Receives: Nothing ; Returns: EDX = offset of message ;------------------------------------------------ mov edx,OFFSET msg4 ;msg4 into edx call Crlf ;endl call Crlf ;endl ret ;return Process_4 ENDP ;------------------------------------------------ Process_5 PROC ; ; Receives: Nothing ; Returns: EDX = offset of message ; Sets CF = 1 to signal end of program ;------------------------------------------------ mov edx,OFFSET msg5 ;msg5 into edx call Crlf ;endl call Crlf ;endl call WriteString ;display message call Crlf ;endl stc ;CF = 1 jc ExitProg ;if CF=1 then jump to Global ExitProg Process_5 ENDP END main
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.