如何在C程序和汇编程序之间发送数据[关闭]

oxf4rvwz  于 2023-05-16  发布在  其他
关注(0)|答案(1)|浏览(132)

**关闭。**这个问题是not reproducible or was caused by typos。目前不接受答复。

此问题是由打印错误或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这一个是解决的方式不太可能帮助未来的读者。
7天前关闭
Improve this question
我一直在尝试为X16模拟器编写简单的IO消息,但是由于stdio库的原因,用C语言编写这些消息最终会变得非常臃肿。因此,我想同时使用C和Assembly。但是,我似乎不能将参数从我的C文件发送到汇编文件。现在,我想将一个字符串地址作为参数从C发送到Assembly,以便Assembly文件可以打印它,但这最终导致文件打印随机字符。下面是我的C代码:

#include <stdio.h>
#include "print.h"

//Function declaration for the assembly routine
    extern void helloasm();

    void main(void) {
        unsigned char msg = "Hello, There";

        //In the assembly, this routine will be called "_helloasm"
        helloasm(&msg);

    }

下面是我用来在C和Asm之间发送消息的头文件:

extern void __fastcall__ helloasm(void *address);

最后是我的汇编源代码:”

;65C02 instruction set
.pc02

;Kernal subroutines and definitions
.include "x16.inc"

;Switch to code segment
.code

;Our "Hello ASM" function, called from the C code
    .export _helloasm

    .proc _helloasm

        stx ZP_PTR_1+1
        sta ZP_PTR_1

        jsr println

        ;Return back to the caller
        rts
    .endproc

    ;Print ASCII text to screen, at the given address in ZP_PTR_1
    .proc println
        ;Y register will be the iterator (so max 256 character strings allowed) 
        ldy #0
    @charloop:
        ;Load the current character
        lda (ZP_PTR_1), y
        ;If it is a string terminator (\0) we stop
        beq @done
        ;Otherwise we print it
        jsr CHROUT
        ;Next character
        iny
        ;If the counter overflows, we stop, else we go back to the loop
        bne @charloop
    @done:
        rts
    .endproc

    ;Read-only data segment (to store text, characters, etc.)
    ;Note that characters are not the same on the X16 as in regular ASCII
    ;so some text will look different if you check the .prg in a hex editor
    .rodata

该程序不断打印一个白色块,其中有黑色条纹通过它。

f2uvfpb9

f2uvfpb91#

我设法解决了这个问题,原来我只是在C源代码中声明变量Msg时忘记了方括号。

unsigned char msg[] = "Hello, There";

相关问题