-
Notifications
You must be signed in to change notification settings - Fork 0
/
sum.asm
58 lines (51 loc) · 1.26 KB
/
sum.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
; 8080 assembler code
.hexfile sum.hex
.binfile sum.com
; try "hex" for downloading in hex format
.download bin
.objcopy gobjcopy
.postbuild echo "OK!"
;.nodump
; OS call list
PRINT_B equ 1
PRINT_MEM equ 2
READ_B equ 3
READ_MEM equ 4
PRINT_STR equ 5
READ_STR equ 6
; Position for stack pointer
stack equ 0F000h
org 000H
jmp begin
; Start of our Operating System
GTU_OS: PUSH D
push D
push H
push psw
nop ; This is where we run our OS in C++, see the CPU8080::isSystemCall()
; function for the detail.
pop psw
pop h
pop d
pop D
ret
; ---------------------------------------------------------------
; YOU SHOULD NOT CHANGE ANYTHING ABOVE THIS LINE
;This program adds numbers from 0 to 10. The result is stored at variable
; sum. The results is also printed on the screen.
sum ds 2 ; will keep the sum
begin:
LXI SP,stack ; always initialize the stack pointer
mvi c, 10 ; init C with 10
mvi a, 0 ; A = 0
loop:
ADD c ; A = A + C
DCR c ; --C
JNZ loop ; goto loop if C!=0
STA SUM ; SUM = A
LDA SUM ; A = SUM
; Now we will call the OS to print the value of sum
MOV B, A ; B = A
MVI A, PRINT_B ; store the OS call code to A
call GTU_OS ; call the OS
hlt ; end program