我正在尝试在 16 位实模式操作系统中创建返回时间和日期的命令。但是,当我从 RTC 读取数据时,会返回一些奇怪的值。根据 RTC,似乎每分钟 90 秒和每小时 90 分钟。
下面,您会看到一段代码应该在 0 到 59 秒之间打印,但在 0 到 89 之间打印:
get_seconds:
  xor ax, ax        ; clear AX
  mov al, 0x00      ; get seconds
  out 0x70, al      ; set index
  in al, 0x71       ; load index to AL
  call print_decimal        ; print contents of AX as decimal
print_decimal:
  lea si, [decimal_str+9]   ; point SI to last byte in buffer
  mov cx, 10        ; 10 = divisor for base 10 printing
 .loop
  xor dx, dx        ; clear DX
  div cx            ; AX = AX / 10, remainder in DX
  add dl, '0'       ; convert remainder to ASCII
  dec si            ; store digits from right to left
  mov [si], dl      ; store remainder as ASCII in the buffer
  test ax,ax        ; check if AX = 0
  jz .print         ; if AX = 0, print decimal-string
  jmp .loop 
 .print
  mov bx, si        ; set BX to last stored ASCII-digit
  call print_string     ; regular int 10h string printer
 .done 
  ret
decimal_str: times 10 db 0  ; buffer