Skip to content

Instantly share code, notes, and snippets.

@mistificator
Last active December 3, 2019 21:55
Show Gist options
  • Save mistificator/48297c215296b37033b63da29fb34959 to your computer and use it in GitHub Desktop.
Save mistificator/48297c215296b37033b63da29fb34959 to your computer and use it in GitHub Desktop.
CP/M example that prints command line arguments
; CP/M example that prints command line arguments
.org $100 ; standard CP/M offset
ld hl,$0080 ; command line arguments address
ld a, (hl)
or a
ret z
inc hl
Loop:
inc hl
ld a, (hl)
or a
ret z
ld e, a
ld c, $02 ; routine $02
push hl
call $0005 ; call BDOS vector
pop hl
jr Loop
End:
ret
; CP/M example that prints command line arguments
.org $100 ; standard CP/M offset
ld hl,$0080 ; command line arguments address
ld a,(hl) ; get arguments length
or a ; check length
ret z ; zero length, exit
xor b ; set zero high byte
ld c, a ; low byte contains length
inc hl ; +1, skip length
ld d, h ; copy address
ld e, l ; to de
add hl,bc ; move to end of string
inc de ; +1, skip preceeding space
ld (hl), '$' ; change 0 to '$'
ld c, $09 ; print string BDOS routine
push hl ; store hl
call $0005 ; call BDOS vector
pop hl ; restore hl
xor (hl) ; change '$' back to 0
ret
@mistificator
Copy link
Author

cmdargs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment