Possible stack overflow in assembly code
hi i'm having a problem with a date program i'm trying to write in assembly language with nasm ,the program works correctly but when i run it, it displays my date along with foreign symbols, i think its a problem with the stack. how do i fix this, please help me :-(
this is the program
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 开发者_如何学Pythonconvert
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
I think the String to be displayed here is not terminated with the $
sign - it probably displayes charaters up until it reaches byte representing $
(36) somewhere in the memory, this might be the cause of displaying the artificial characters.
I thought you should use offset
when printing out strings too (see example).
精彩评论