在Assembly中为打印功能创建和访问局部变量

问题描述 投票:0回答:1

我正在学习装配,我正在掌握它。但有一件事我无法开展工作。

为了通过串行总线在显示器上打印信息,我做了一个打印功能。

在C中我编写了自己的打印函数,它被称为print("hello world");。打印函数是一个简单的while循环,它使用指针在Tx缓冲区中设置字节。 uController使用代码内存作为字符串而不是xdata内存和代码内存。

在集会中,我现在试图做出类似的东西。我相信我的打印功能正常工作(是吗?)。我相信问题在于变量,它的范围以及我声明/初始化字符串的地方。

结合打印功能,我使用一个设置位置功能,它使用r6和r7以及一个特定的指令字节来设置显示器的写入位置。

setposa  mov   a,#setapos     ;set position x-y
         lcall chrout
         mov   a,r6         ;x position
         lcall chrout
         mov   a,r7         ;y position
         lcall chrout
         ret 



print       lcall setposa   
print1      movx a, @dptr   ; put the character in a (used by chrout)
            jz print2       ; if charac is not /0, print it else jump to end
            lcall chrout
            inc dptr
            jmp print1
print2      ret 

我用这些行调用print函数:

;tab_bas   db 'this is a string',0  ; SHOULD NOT BE HERE?, DOES NOT WORK!! send tons of data to display resulting in a crash  I believe this line of code never runs  
s08p44    clr stepkey           ; clear this bit for re-use
tab_bas   db 'this is a string',0   ;having it here seems not to do anything, nothing happens   
          mov r6,#5
          mov r7,#6             ; set position for the text
          mov dptr, #tab_bas    ; set datapointer at text to print
          call print            ; print the text at desired position
          jmp s08p38            ; jump to ret instruction

我想创建一个本地字符串变量,使用r6和r7设置x和y,然后打印本地字符串变量。 chrout功能不是我的,并且被证明有效。它将A的内容放在Tx缓冲区中,并在缓冲区为空时设置transmitt标志。

我还不太了解变量的范围,足以理解为什么它不起作用。我还尝试在存储所有其他变量的地方声明字符串,但这也不起作用。

我怎样才能让它发挥作用?

另外:当ram受限时,字符串将被放入xdata内存中。但我更喜欢使用代码存储器。这可以通过相对简单的方式完成吗?

附加信息:我正在编程8051软核,我正在使用AVOCET A51汇编程序。

assembly local-variables 8051
1个回答
1
投票

解决方案是在print函数中使用movc指令而不是movx来正确地让数据指针指向表(单个字符串)

print       lcall setposa
print1      clr a
            movc a,@ a + dptr       ; set datapointer at text to print
            jz print2       ; if charac is not /0, print it else jump to end
            lcall chrout
            inc dptr
            jmp print1
print2      ret
© www.soinside.com 2019 - 2024. All rights reserved.