So, I'm just found code from this question. I'm trying to print the current time in hours, but output not expected.
This is screenshoot for wroing output
Expected output is current time : 14 16 (secs)
BITS 16 ORG 0x7C00 _start: mov ax, 07C0h add ax, 288 mov ss, ax ; ss = stack space mov sp, 4096 ; sp = stack pointer mov ax, 07C0h mov ds, ax ; ds = data segment call time call cvthrs call cvtmin call cvtsec call dsptime cli endloop: hlt jmp endloop time: ;Get time from the system mov ah,02h int 1Ah ;ret ;CH - Hours ;CL - Minutes ;DH - Seconds cvthrs: ;Converts the system time from BCD to ASCII mov bh,ch ;copy contents of hours (ch) to bh shr bh, 4 add bh,30h ;add 30h to convert to ascii mov [tmfld],bh mov bh,ch ;and bh,0fh add bh,30h mov [tmfld + 1],bh ret cvtmin: mov bh,cl ;copy contents of minutes (cl) to bh shr bh, 4 add bh,30h ;add 30h to convert to ascii mov [tmfld + 3],bh mov bh,cl and bh,0fh add bh,30h mov [tmfld + 4],bh ret cvtsec: mov bh,dh ;copy contents of seconds (dh) to bh shr bh, 4 add bh,30h ;add 30h to convert to ascii mov [tmfld + 6],bh mov bh,dh and bh,0fh add bh,30h mov [tmfld + 7],bh ret tmfld: db '00:00:00' dsptime: ;Display the system time mov ah,13h ;function 13h (Display String) mov al,0 ;Write mode is zero mov bh,0 ;Use video page of zero mov bl,0x0f;Attribute mov cx,8 ;Character string is 8 long mov dh,5 ;position on row 5 mov dl,0;and column 0 push ds ;put ds register on stack pop es ;pop it into es register lea bp,[tmfld] ;load the offset address of string into BP int 10H ret
Compile and run using QEMU:
nasm time.asm -fbin -o time.img
qemu-system-i386 -drive format=raw,file=./time.img
How to fix this ?
int 21h
calls, justint 1ah
andint 10h
which are both BIOS, aren't they? I only skimmed / searched the code, but your first 2 points don't seem to match this code.org 7c00h
is a big problem, though, if setting segment registers to something other than 0, and yes havingtime
fall through intocvthrs
instead of running aret
seems weird. – Peter Cordes