-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter 6 Exercises.txt
More file actions
123 lines (114 loc) · 2.66 KB
/
Chapter 6 Exercises.txt
File metadata and controls
123 lines (114 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
TITLE Boolean Calculator 1 (BooleanCalc1.asm)
; This functions as a simple boolean calculator for 32-bit integers.
INCLUDE Irvine32.inc
.data
CaseTable BYTE '1' ;lookup value
DWORD x_AND_y ;address of procedure
EntrySize = ($-CaseTable)
BYTE '2'
DWORD x_OR_y
BYTE '3'
DWORD NOT_x
BYTE '4'
DWORD x_XOR_y
BYTE '5'
DWORD Exit_Program
NumberOfEntries = ($-CaseTable)/EntrySize
prompt BYTE "Press 1. x AND y, 2. x OR y, 3. NOT x, 4. x XOR y, 5. Exit ",0
msg1 BYTE "x AND y ",0
msg2 BYTE "x OR y ",0
msg3 BYTE "NOT x ",0
msg4 BYTE "x XOR y ",0
msg5 BYTE "Exit Program ",0
promptx BYTE "Enter an x in Hexadecimal: ",0
prompty BYTE "Enter an y in Hexadecimal: ",0
.code
main PROC
mov edx,OFFSET prompt ;ask user for input
call WriteString
call ReadChar ;read character into AL
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
jmp L3 ;exit the search
L2:
add ebx,EntrySize ;point to the next entry
loop L1 ;repeat until ECX = 0
L3:
exit
main ENDP
x_AND_y PROC
call Crlf
mov edx,OFFSET msg1
call WriteString
call Crlf
mov edx,OFFSET promptx ;ask user for input
call WriteString
call ReadHex ;read decimal into EAX
mov EBX,EAX
call Crlf
mov edx,OFFSET prompty ;ask user for input
call WriteString
call ReadHex ;read decimal into EAX
AND EAX,EBX
call WriteHexB
ret
x_AND_y ENDP
x_OR_y PROC
call Crlf
mov edx,OFFSET msg2
call WriteString
call Crlf
mov edx,OFFSET promptx ;ask user for input
call WriteString
call ReadHex ;read decimal into EAX
mov EBX,EAX
call Crlf
mov edx,OFFSET prompty ;ask user for input
call WriteString
call ReadHex ;read decimal into EAX
OR EAX,EBX
call WriteHexB
ret
x_OR_y ENDP
NOT_x PROC
call Crlf
mov edx,OFFSET msg3
call WriteString
call Crlf
mov edx,OFFSET promptx ;ask user for input
call WriteString
call ReadHex ;read decimal into EAX
NOT eax
call WriteHexB
ret
NOT_x ENDP
x_XOR_y PROC
call Crlf
mov edx,OFFSET msg4
call WriteString
call Crlf
mov edx,OFFSET promptx ;ask user for input
call WriteString
call ReadHex ;read decimal into EAX
mov EBX,EAX
call Crlf
mov edx,OFFSET prompty ;ask user for input
call WriteString
call ReadHex ;read decimal into EAX
XOR EAX,EBX
call WriteHexB
ret
x_XOR_y ENDP
Exit_Program PROC
call Crlf
mov edx,OFFSET msg5
call WriteString
ret
Exit_Program ENDP
END main