From 2a5d0fa9679dea299752cd51b3f60ed10e9c9532 Mon Sep 17 00:00:00 2001 From: Jali Date: Sun, 15 Sep 2024 00:20:02 +0200 Subject: [PATCH] Added a 'hello world' program --- src/HELLO.ASM | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/HELLO.ASM diff --git a/src/HELLO.ASM b/src/HELLO.ASM new file mode 100644 index 0000000..132b3a5 --- /dev/null +++ b/src/HELLO.ASM @@ -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