Do all this question and make it as menu button
5. Ask the user to input a number. Test if this number is odd or even. Display it on the screen. Tips: Use the AND instruction to check the least significant bit of the number. If it is 1, the number is odd, else it is even.
6. Ask the user to input 2 numbers. Run the 2 numbers through the logic tests of AND, OR, and XOR. Display the results on the screen.(Note: run the between the two numbers : e.g. Number1 AND Number2
Solution
TITLE MASM Template
(main.asm)
COMMENT !
Section:01
Group:5A
Student Name 1:AHMAD KHAIDIR AMIR BIN RODZMAN
Student Name 2:
Date:
!
INCLUDE Irvine32.inc
.data
STR1 BYTE "PLEASE ENTER NUMBER > ",0H
STR2 BYTE " IS AN ODD NUMBER.",0H
STR3 BYTE " IS AN EVEN NUMBER.",0H
STRING1 BYTE "PLEASE ENTER NUMBER > ",0H
STRING2 BYTE "--------------------------------",0H
STRING3 BYTE " = ", 0H
STRINGAND BYTE " AND ",0H
STRINGOR BYTE " OR ",0H
STRINGXOR BYTE " XOR ",0H
STR5 BYTE "Total sum : ",0H
STR6 BYTE " The smallest : ",0H
STR7 BYTE " The largest : ",0H
STR9 BYTE "Thank you",0H
STRMENU BYTE "Menu: ",0H
STRI1 BYTE "PLEASE ENTER NUMBER > ",0H
STRI2 BYTE " is larger than ",0H
STRI3 BYTE " is smaller than ",0H
STRI4 BYTE " is equal to ",0H
STRADD BYTE " + ",0H
STREQL BYTE " = ",0H
STRCHOICE BYTE "Your choice is=",0
STRMENU1 BYTE "[1].Odd or Even ",0H
STRMENU2 BYTE "[2].Operation AND,OR,XOR ",0H
STRMENU3 BYTE "[3].Addition and Comparison ",0H
STRMENU4 BYTE "[4].Exit ",0H
SELECT DWORD ?
NUM DWORD ? , ?
VALUE1 DWORD ?
VALUE2 DWORD ?
VAL1 DWORD ?
VAL2 DWORD ?
VAL3 DWORD ?
VAL4 DWORD ?
TestArray SDWORD -10,49,56,23,2,-121,92,15,9,-8
TOTAL SDWORD ? ;SDWORD=Signed DWORD
SMALLEST SDWORD ? ;SDWORD=Signed DWORD
LARGEST SDWORD ? ;SDWORD=Signed DWORD
.code
main PROC
MENU:
mov edx,offset STRMENU
CALL WriteString
CALL crlf
mov edx,offset STRMENU1
CALL WriteString
CALL crlf
mov edx,offset STRMENU2
CALL WriteString
CALL crlf
mov edx,offset STRMENU3
CALL WriteString
CALL crlf
mov edx,offset STRMENU4
CALL WriteString
CALL crlf
mov edx,offset STRCHOICE
CALL WriteString
CALL crlf
CALL ReadDec ;READ USER INPUT
MOV SELECT,EAX;STORE USER INPUT
CMP SELECT,1
JE HERE1
CMP SELECT,2
JE HERE2
CMP SELECT,3
JE HERE3
CMP SELECT,4
JE HERE4
HERE1:
MOV EDX, OFFSET STR1
CALL WriteString
CALL ReadDec
; READ USER INPUT
MOV NUM,EAX
; STORE USER INPUT IN NUM ARRAY,eax function to store user input
MOV EDX, OFFSET STR1
CALL WriteString
CALL ReadDec
;READ USER INPUT
MOV NUM+4,EAX
; STORE USER INPUT IN NUM ARRAY,eax function to store user input
MOV ECX,2
; SET COUNTER TO 2
MOV EBX,0
L1:
MOV EAX,NUM[EBX]
AND EAX,1
; PERFORM BOOLEAN AND BETWEEN EACH BIT IN EAX AND ;1
CMP EAX,0
; COMPARE VALUE OF EAX WITH 0
JZ NUMEVEN
; IF ZEROFLAG IS 1, JUMP TO NUMEVEN
mov EAX,NUM[EBX]
CALL WriteDec
MOV EDX,OFFSET STR2
CALL WriteString
CALL crlf
JMP FINAL
; JUMP TO FINAL
NUMEVEN:
mov EAX, NUM[EBX]
CALL WriteDec
MOV EDX,OFFSET STR3
CALL WriteString
CALL crlf
JMP FINAL
FINAL:
ADD EBX, 4
LOOP L1
JMP MENU
HERE2:
MOV EDX, OFFSET STRING1
CALL WriteString
CALL ReadDec
; READ USER INPUT
MOV VALUE1,EAX
; MOVE USER INPUT TO VAL1
MOV EDX, OFFSET STRING1
CALL WriteString
CALL ReadDec
; READ USER INPUT
MOV VALUE2,EAX
; MOVE USER INPUT TO VAL2
MOV EAX, VALUE1
CALL WriteDec
MOV EDX, OFFSET STRING3
CALL WriteString
MOV EAX, VALUE1
CALL WriteBin
; PRINT VAL1 IN BINARY FORM
CALL crlf
MOV EAX, VALUE2
CALL WriteDec
MOV EDX, OFFSET STRING3
CALL WriteString
MOV EAX, VALUE2
CALL WriteBin
; PRINT VAL2 IN BINARY FORM
CALL crlf
MOV EDX, OFFSET STRING2
CALL WriteString
CALL crlf
MOV EAX, VALUE1
CALL WriteDec
MOV EDX, OFFSET STRINGAND
CALL WriteString
MOV EAX, VALUE2
CALL WriteDec
MOV EDX, OFFSET STRING3
CALL WriteString
MOV EAX, VALUE1
AND EAX, VALUE2
; PERFORM BOOLEAN AND BETWEEN EACH BITS IN EAX AND VAL2
CALL WriteDec
; PRINT VALUE OF EAX
CALL crlf
MOV EAX, VALUE1
CALL WriteDec
MOV EDX, OFFSET STRINGOR
CALL WriteString
MOV EAX, VALUE2
CALL WriteDec
MOV EDX, OFFSET STRING3
CALL WriteString
MOV EAX, VALUE1
OR EAX, VALUE2
; PERFORM BOOLEAN OR BETWEEN EACH BITS IN EAX AND VAL2
CALL WriteDec
; PRINT VALUE OF EAX
CALL crlf
MOV EAX, VALUE1
CALL WriteDec
MOV EDX, OFFSET STRINGXOR
CALL WriteString
MOV EAX, VALUE2
CALL WriteDec
MOV EDX, OFFSET STRING3
CALL WriteString
MOV EAX, VAL1
XOR EAX, VAL2
; PERFORM BOOLEAN XOR BETWEEN EACH BITS IN EAX AND VAL2
CALL WriteDec
; PRINT VALUE OF EAX
CALL crlf
JMP MENU
HERE3:
MOV EDX, OFFSET STRI1
CALL WriteString
CALL ReadDec
; READ USER INPUT
MOV VAL3,EAX
; MOVE USER INPUT TO VAL1
MOV EDX, OFFSET STRI1
CALL WriteString
CALL ReadDec
; READ USER INPUT
MOV VAL4,EAX
; MOVE USER INPUT TO VAL2
MOV EAX,VAL3
CALL WriteDec
MOV EDX, OFFSET STRADD
CALL WriteString
MOV EAX,VAL4
CALL WriteDec
MOV EDX, OFFSET STREQL
CALL WriteString
ADD EAX, VAL3
CALL WriteDec
CALL crlf
MOV EAX, VAL3
CMP EAX, VAL4
JA LARGER
JB LOWER
JMP EQUAL
LARGER:
MOV EAX,VAL3
CALL WriteDec
MOV EDX, OFFSET STRI2
CALL WriteString
MOV EAX,VAL4
CALL WriteDec
JMP MENU
LOWER:
MOV EAX,VAL3
CALL WriteDec
MOV EDX, OFFSET STRI3
CALL WriteString
MOV EAX,VAL4
CALL WriteDec
JMP MENU
EQUAL:
MOV EAX,VAL4
CALL WriteDec
MOV EDX, OFFSET STRI4
CALL WriteString
MOV EAX,VAL4
CALL WriteDec
JMP MENU
HERE4:
exit
main ENDP
END main
0 Comments