• Please review our updated Terms and Rules here

Program Error w/ BDOS Function 9 (Print String)

KKat

New Member
Joined
May 15, 2015
Messages
5
Hey all,

I've been playing around with the YAZE implementation of CP/M, and have written a few simple programs. Now I'm trying to use BDOS function 9 to print a $-terminated string. The program assembles and runs, and I can see the terminated string in the hex dump, but when I make the call, it prints the string and then a bunch of garbage characters. The really odd thing is that it doesn't print the last character before the $ delimiter; for example:

"Hello, World!$" prints as "Hello, World" followed by garbage
"Hello, World$" prints as "Hello, Worl" followed by garbage

I think that for some reason, the CCP isn't seeing the $ delimiter (hence the garbage), but I can't figure out why, since it is correct in the hex dump. And I have NO idea why the last printable character doesn't print, regardless of string length.

Thanks in advance for any help.

KKat

P.S. I believe YAZE emulates v. 3.1; haven't written a program to check the version myself yet, though
 
Is it possible that you've put the $ outside of the quotation marks? If you have, it is no longer terminating the string. It really sounds like the memory is being overwritten or that there is no $ to start with!

Hey all,

I've been playing around with the YAZE implementation of CP/M, and have written a few simple programs. Now I'm trying to use BDOS function 9 to print a $-terminated string. The program assembles and runs, and I can see the terminated string in the hex dump, but when I make the call, it prints the string and then a bunch of garbage characters. The really odd thing is that it doesn't print the last character before the $ delimiter; for example:

"Hello, World!$" prints as "Hello, World" followed by garbage
"Hello, World$" prints as "Hello, Worl" followed by garbage

I think that for some reason, the CCP isn't seeing the $ delimiter (hence the garbage), but I can't figure out why, since it is correct in the hex dump. And I have NO idea why the last printable character doesn't print, regardless of string length.

Thanks in advance for any help.

KKat

P.S. I believe YAZE emulates v. 3.1; haven't written a program to check the version myself yet, though
 
Thanks for the replies; I think you are right about the $-terminator not being processed correctly, but I'm not sure why. Here is the code:


; Directives and defines

#charset ascii
#target rom

BOOT equ 0x0000 ; Default CP/M addresses
TPA equ 0x0100
BDOS equ 0x0005
print_string equ 0x09 ; BDOS function refs

#code _CODE, TPA

ld sp, stack ; Set up stack

ld c, print_string ; BDOS function 0x09
ld de, msg1 ; Point DE to string to print
call BDOS ; Print it.

jp BOOT ; Jump to BOOT to end program

; Define user input message

msg1:
.ascii 'Enter some text$'

; Allocate unused space at end to stack

stack:
end
 
I figured it out: by allocating the space right after the message string to the stack, I was overwriting the last two characters of the string when I called BDOS. I added two NOP instructions after the string (but before the "stack" label), and now the program runs correctly.

I know I don't need to allocate an internal stack for a simple program like this, but I wanted to get in the habit in preparation for longer programs. Where do you typically put the stack on a CP/M program? Is there a "standard" place to put it, or is it just up to the individual programmer?

Thanks,

KKat
 
The 'stack' is actually missing.

The stack pointer (SP) is set up to point to the label stack: and a call made to BDOS - which pushes the return address onto the stack (which doesn't exist) and promptly corrupts the last two bytes of the text message (t$) - hence the reason the BDOS function 'crashes' through memory.

There needs to be some uninitialised space between the end of your message and the label 'stack:' to actually contain the stack. The stack works its way down from it's initial point (not upwards).

Dave
 
Try changing your "jp BOOT" to "ret"

This works fine in CP/M:

Code:
        ORG     100H
        MVI     C,9
        LXI     D,MSG
        CALL    5
        RET
MSG:    DB      'HELLO WORLD$'
 
Thanks, everyone, for the replies; I got it to work.

KKat
 
Back
Top