-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject.asm
More file actions
63 lines (59 loc) · 3 KB
/
Copy pathProject.asm
File metadata and controls
63 lines (59 loc) · 3 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
;uProcessor Midterm Project
;File name: Project.asm
;Date: 2019/10/30
;Author: Yu Shan Huang
;StudentID: B10707049
;National Taiwan University of Science Technology
;Department of Electrical Engineering
include ProjectPrint.h
include getNum.h
include MathCompute.h
.model small
.data
str1 db "Please enter two numbers between 1 to 99:" ,10,13,'$'
error_message db 10, 13, "Error Format. Please enter numbers between 1 to 99", 10, 13, "The example format is like 20 50. Please enter again!", 10 ,13, '$'
str2 db 10, 10, 13, "in Hex: $"
str3 db 10, 10, 13, "in Decimal: $"
str4 db 10, 13, "GCD is $"
str5 db 10, 13, "LCM is $"
str6 db 10, 10, 13, "Press esc to exit. Press other keys to continue. ", 10, 13, '$'
NumStore db 5 dup(?)
mul_result dw ?
.stack 100h
.code
main proc
mov ax, @data
mov ds, ax
Program_Start: ;Program start at here
printStr str1 ;Print "Please enter two numbers between 1 to 99:"
getNum NumStore, error_message ;Get keyboard input. Two parameters.
DataConvertion: ;Received keyboard input, starting computation.
ASCIIDecimal NumStore ;ASCIIDecimal from mathCompute.h
Combine NumStore ;Combine from mathCompute.h
Computation mul_result ;Computation from mathCompute.h Retun GCD at CX register, LCM at AX register
printStr str2 ;Print "in Hex:"
printStr str4 ;Print "GCD is "
printNum NumStore ;Print GCD in Hex
printStr str5 ;Print "LCM is "
push cx ;push GCD
mov cx, ax ;mov LCM to CX
printNum NumStore ;Print LCM in hex
pop bx ;pop GCD
push cx ;push LCM
HextoDecimal NumStore ;HextoDecimal from mathCompute.h Result will be stored in NumStore
printStr str3 ;Print "in Decimal:"
printStr str4 ;Print "GCD is "
printStr NumStore ;Print GCD in Decimal
pop bx ;pop LCM
HextoDecimal NumStore ;HextoDecimal from mathCompute.h Result will be stored in NumStore
printStr str5 ;Print "LCM is"
printStr NumStore ;Print LCM is Decimal
printStr str6 ;Print "Press esc to exit. Press other keys to continue. "
mov ah, 00h ;Wait for keystroke
int 16h
cmp al, 1bh ;if input equals to esc, program terminates.
jne Program_Start
mov ax, 4c00h ;exit to DOS
int 21h
main endp
end main