-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfahrenheit.asm
87 lines (62 loc) · 1.4 KB
/
fahrenheit.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
; centigrade (celsius) to fahrenheit calculation and vice-versa.
; it may not be accurate, because of integer division.
; this program prints out the result in binary code.
; to see result in hexadecimal or decimal form click vars.
name "celsi"
org 100h
jmp start
tc db 10 ; t celsius.
tf db 0 ; t fahrenheit.
result1 db ? ; result in fahrenheit.
result2 db ? ; result in celsius.
start:
; convert celsius to fahrenheit according
; to this formula: f = c * 9 / 5 + 32
mov cl, tc
mov al, 9
imul cl
mov cl, 5
idiv cl
add al, 32
mov result1, al
mov bl, result1
call print ; print bl
; convert fahrenheit to celsius according
; to this formula: c = (f - 32) * 5 / 9
mov cl, tf
sub cl, 32
mov al, 5
imul cl
mov cl, 9
idiv cl
mov result2, al
mov bl, result2
call print ; print bl
; wait for any key press...
mov ah, 0
int 16h
ret ; return to the operating system.
; procedure prints the binary value of bl
print proc near
pusha
; print result in binary:
mov cx, 8
p1: mov ah, 2 ; print function.
mov dl, '0'
test bl, 10000000b ; test first bit.
jz zero
mov dl, '1'
zero: int 21h
shl bl, 1
loop p1
; print binary suffix:
mov dl, 'b'
int 21h
; print carrige return and new line:
mov dl, 0Dh
int 21h
mov dl, 0Ah
int 21h
popa
ret ; return to the main program.
print endp