-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.asm
92 lines (82 loc) · 2.69 KB
/
main.asm
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
;assignment 3
INCLUDE Irvine32.inc
.data
stringSize = 80d
stringInput BYTE stringSize+1 DUP (?)
comparisonHex BYTE 'h'
hexDigits BYTE "0123456789ABCDEFabcdef"
hexSize = 22d
count dword ?
noH BYTE "There is no h at the end of the number"
isHex BYTE "Congrats, the number you entered is in the correct format"
notHex BYTE "This entry is not in the correct format"
.code
main PROC
StateA: ;check if number is hex
call getString ;calls function to get the string from a user
call checkHex ;move the last character into the al
main ENDP
;======================================================================;
;= Runs through the function to determine if each char is a hex digit =;
;= =;
;======================================================================;
checkHex Proc
mov esi, 0 ;set string pointer to zero
mov edi, 0 ;set string pointer to zero
mov ecx, sizeof stringInput
loop1:
mov count, ecx ;save outer loop size
mov ecx, hexSize ;set inner loop size
mov ah, stringInput[edi]
InnerLoop:
mov al, hexDigits[esi]
.IF al == ah
inc esi
.ELSEIF ah == 'h'
call stateC
.ENDIF
loop InnerLoop
mov ecx,count
inc edi
loop Loop1
call stateB
ret
checkHex ENDP
;=====================================================================;
;= Gets a string from the user =;
;= =;
;=====================================================================;
getString Proc
mov edx, OFFSET StringInput
mov ecx,stringSize
call ReadString
ret
getString ENDP
;=====================================================================;
;= If there is no H at the end of the number jump here =;
;= =;
;=====================================================================;
StateB Proc
mov edx, OFFSET noH
call WriteString
exit
StateB ENDP
;=====================================================================;
;= This is a hex number =;
;= =;
;=====================================================================;
StateC Proc
mov edx, OFFSET isHex
call WriteString
exit
StateC ENDP
;=====================================================================;
;= Not a hex number =;
;= =;
;=====================================================================;
StateD Proc
mov edx, OFFSET notHex
call WriteString
exit
StateD ENDP
END main