gpt4 book ai didi

assembly - 汇编代码中可能出现堆栈溢出

转载 作者:行者123 更新时间:2023-12-04 06:30:25 24 4
gpt4 key购买 nike

嗨,我的日期程序有问题,我正在尝试用 nasm 用汇编语言编写,该程序工作正常,但是当我运行它时,它显示我的日期和外来符号,我认为这是堆栈的问题.我该如何解决这个问题,请帮帮我:-(

这是程序

org 100h
bits 16d

section .data

endProg db 0ah,0dh,"Program Terminated","$"
year db 0, 0, '\'
month db 0, 0, '\'
day db 0ah,0dh, 0
skipLine db 0ah,0dh
hour db 0,0, ':'
min db 0, 0, ':'
sec db 0, 0, ' '

section .bss

section .text

start:

call clear_screan

; get date
mov ah, 2ah
int 21h

; year
add cx, 0f830h
mov ax, cx
call convert
mov [year], ax

; month
mov al, dh
call convert
mov [month], ax

; day
mov al, dl
call convert
mov [day], ax

mov ax,skipLine

; get time
mov ah, 2ch
int 21h

; hour
mov al, ch
call convert
mov [hour], ax

; minute
mov al, cl
call convert
mov [min], ax

; second
mov al, dh
call convert
mov [sec], ax

pop ax
mov ax,skipLine

;display output
mov dx,year
mov ah,09h
int 21h

mov DX,endProg
mov AH,09h
int 21h

int 20h

;..................processes...........................

clear_screan:
mov AX,03h
int 10h
ret

convert:
push cx
xor ah, ah
mov cl, 10
div cl
add ax, 3030h
pop cx
ret

最佳答案

;display output
mov dx,year
mov ah,09h
int 21h

我认为此处显示的字符串没有以 $ 结尾。符号 - 它可能会显示字符直到它到达代表 $ 的字节(36) 在内存的某处,这可能是显示人工字符的原因。

我认为你应该使用 offset也打印字符串时(请参阅 example )。

关于assembly - 汇编代码中可能出现堆栈溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5482788/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com