Added a 'hello world' program

This commit is contained in:
2024-09-15 00:20:02 +02:00
parent 9ec2e1b081
commit 2a5d0fa967

39
src/HELLO.ASM Normal file
View File

@@ -0,0 +1,39 @@
; This is an example of the Hello, World program.
; This will define a function to print a string on the screen.
; Uses 8080 assembler mnemonics.
ORG 100H ; CPM programs start address
JMP START ; go to program start
; Variable storage space.
MsgStr: DB 13,10,'Hello, world.',13,10,0
Stack: DW 0 ; place to save the old stack
SBOT: DS 32 ; reserve a local stack
; Constants
STOP: EQU $-1 ; top of our stack
BDOS: EQU 5 ; adress of the BDOS call
; Start of the code segment
; PRINTF: Prints a string on the screen using a BDOS function.
; The address of the string is expected to be in register HL.
PRINTF:
PRLOOP: MOV A, M ; read next char
ORA A ; check, if string has ended
JZ PREND ; if char == 0, then leave the loop
MOV E, A ; load the char into E
MVI C, 2 ; load BDOS function id 2 into C
PUSH H ; save the HL register
CALL BDOS ; call the BDOS function
POP H ; restore the HL register
INX H ; point to the next char
JMP PRLOOP ; do the next char
PREND: RET ; return from subroutine
; Start of the main code block
START: LXI H, 0 ; blank out HL
DAD SP ; HL = SP
SHLD Stack ; save the original stack
LXI H, STOP ; set HL to the new stack top
SPHL ; set SP to point to our new stack
LXI H, MsgStr ; load the string addr into HL
CALL PRINTF ; call our self defined print routine
LHLD Stack ; load original stack addr into HL
SPHL ; restore the original stack
RET ; return control back to CP/M
END