![gamingisfun](/avatars/23862.jpg)
gamingisfun
23.03.2020 •
Computers and Technology
Hello, this is a 2 part question for my beginning assembly class. Thank you in advance for your help
Boolean Calculator (1)
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 Program
When the user makes a choice, call a procedure that displays the name of the operation about to be performed.
Boolean Calculator (2)
Continue the solution program from the preceeding exercise by implementing the following procedures:
- AND_op: Prompt the user for two hexadecimal integers. AND them together and display the result in hexadecimal.
-OR_op: Prompt the user for two hexadecimal integers. OR them together and display the result in hexadecimal.
- NOT_op: Prompt the user for two hexadecimal integers. NOT the integer and display the result in hexadecimal.
- XOR_op: Prompt the user for two hexadecimal integers. Exclusive-OR them together and display the result in hexadecimal.
The following is what our professor has given us help with:
Include Irvine32.inc
.data
msgMenu " 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, 0dh, 0ah
BYTE "Enter integer>" , 0
msgAND BYTE "Boolean AND", 0
msgOR BYTE "Boolean OR", 0
msgNOT BYTE "Boolean NOT", 0
msgXOR BYTE "Boolean XOR", 0
msgOperand1 BYTE "Input the first 32--bit hexadecimal operand: ", 0
msgOperand2 BYTE "Input the second 32--bit hexadecimal operand: ", 0
msgResult BYTE "The 32-bit hexadecimal result is: ", 0
Solved
Show answers
More tips
Answers on questions: Computers and Technology
- C Computers and Technology Buenas gente ayuden :((( necesito hacer alguno de esos ejercicios en Pseint con metodos-procedimientos para mañana en la noche y no sé nada : 1. Leer dos valores enteros...
- C Computers and Technology Write a loop to store the letters “f” through “w” in an array named letters. Then, print the contents of the array to the screen....
- C Computers and Technology 2) - How many integers between 1 and 500 inclusive are divisible by either 2, 3, or 5?...
- C Computers and Technology Match the type of information with the section of the business plan it fits in. To match them, click the type of information, and then click the section. How you will differentiate...
- M Mathematics Choose the slope-intercept form of the equation of the line that passes through (-2, 4) and is perpendicular to the graph of 2x + y = -20....
- H History Ancient societies like the Mayans had a social structure similar to Egypt?...
- M Mathematics PLEASE HELP ME PLEASE ANSWER WITHIN THIS HOUR! DO NOT POST ANYTHING FOR THE 40 POINTS** 1. Cite evidence from the text that indicates the narrator’s point of view. What...
- C Chemistry How do the circulatory, respiratory and digestive systems work together to support the process of cellular respiration to maintain homeostasis in cells?...
- M Mathematics Es muy triste reconocerlo, pero el ser humano, a pesar de su vasto saber y de la habilidad increíble de sus manos no ha podido convivir. Ha fracasado en la pedagogía de...
- S SAT What is the coefficient of x3y4 in (-3x + 4y)7?....
Ответ:
Complete code is given below:
Explanation:
INCLUDE Irvine32.inc
.data
msgMenu BYTE " 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",0
msgAND BYTE "Boolean AND",0
msgOR BYTE "Boolean OR",0
msgNOT BYTE "Boolean NOT",0
msgXOR BYTE "Boolean XOR",0
msgOperand1 BYTE "Input the first 32-bit hexadecimal operand: ",0
msgOperand2 BYTE "Input the second 32-bit hexadecimal operand: ",0
msgResult BYTE "The 32-bit hexadecimal result is: ",0
caseTable BYTE '1' # lookup value
DWORD _AND_op # address of the procedure
EntrySize = ($ - caseTable )
BYTE '2'
DWORD _OR_op
BYTE '3'
DWORD _NOT_op
BYTE '4'
DWORD _XOR_op
BYTE '5'
DWORD _ExitProgram
NumberOfEntries=($ - caseTable)/EntrySize
.code
main08stub PROC
call Clrscr
Menu:
mov edx, OFFSET msgMenu # menu choices
call WriteString
call Crlf
L1: call ReadChar
cmp al, '5' # is selection valid (1-5)?
ja L1 # if above 5, go back
cmp al, '1'
jb L1 # if below 1, go back
call Crlf
call **BLANK**
jc quit # if CF = 1 exit
call Crlf
jmp Menu # display menu again
quit: exit
main08stub ENDP
#
**BLANK** PROC
#
# It selects a procedure from the case table
# Receives: AL = number of procedure
# Returns: nothing
#
ret
**BLANK** ENDP
#
_AND_op PROC
#
# Performs a boolean AND operation
# Receives: Nothing
# Returns: Nothing
#
ret
_AND_op ENDP
#
_OR_op PROC
#
# Performs a boolean OR operation
# Receives: Nothing
# Returns: Nothing
#
ret
_OR_op ENDP
#
_NOT_op PROC
#
# Performs a boolean NOT operation.
# Receives: Nothing
# Returns: Nothing
#
ret
_NOT_op ENDP
#
_XOR_op PROC
#
#
# Performs an Exclusive-OR operation
# Receives: Nothing
# Returns: Nothing
#
ret
_XOR_op ENDP
#
_ExitProgram PROC
#
# Receives: Nothing
# Returns: Sets CF = 1 to signal end of program
#
ret
_ExitProgram ENDP
END main08stub
Ответ:
I get 0x55 and this the linking address of the main function.
use this function to see changes:
/* bar6.c */
#include <stdio.h>
char main1;
void p2()
{
printf("0x%X\n", main1);
}
Output is probably 0x0
you can use your original bar6.c with updaated foo.c
char main;
int main() // error because main is already declared
{
p2();
//printf("Main address is 0x%x\n",main);
return 0;
}
Will give u an error
again
int main()
{
char ch = main;
p2(); //some value
printf("Main address is 0x%x\n",main); //some 8 digit number not what printed in p2()
printf("Char value is 0x%x\n",ch); //last two digit of previous line output
return 0;
}
So the pain in P2() gets the linking address of the main function and it is different from address of the function main.
Now char main (uninitialized) in another compilation unit fools the compiler by memory-mapping a function pointer on a char directly, without any conversion: that's undefined behavior. Try char main=12; you'll get a multiply defined symbol main...
Explanation: