Получите метку времени UNIX в секундах - PullRequest
0 голосов
/ 29 марта 2019

Как узнать текущее время UNIX для 8086 asm? Я не мог найти информацию в интернете. Я знаю, что это 32 бита, поэтому он должен заполнить 2 регистра. РЕДАКТИРОВАТЬ: ОС DOS (я использую Dosbox)

1 Ответ

2 голосов
/ 30 марта 2019

Как я могу получить текущее ... время на 8086 АСМ?

Вопрос: «Какую операционную систему вы используете?»

ЦП не имеет каких-либо часов реального времени. И даже в ранних ПК x86 такого не было. Операционная система (или BIOS) знает, как получить системное время.

Как узнать текущее время UNIX для 8086 asm?

Если ваша операционная система не поддерживает время UNIX, но поддерживает время, указанное как «дата» (Y, M, D, ч, м, с), существует только жесткий способ :

Здесь псевдокод :

; Calculate the number of days from 1970/1/1 to 1/1 of this year
; not including the 29ths of February
time = (year-1970)*365

; Calculate the number of 2/29s (leap years) passed since
; 1970/1/1 until today (including 2/29 of this year if this
; year is a leap year!)
leapyears = year-1969
if month > 2:
    ; It is March or later; the 29th of February (if any)
    ; has already passed this year.
    leapyears = leapyears + 1
end-if

; Here "leapyears" has the following value:
;   1970: 1 or 2 => x/4 = 0
;   1971: 2 or 3 => x/4 = 0
;   1972: 3 or 4 => x/4 = 0 or 1
;   1973: 4 or 5 => x/4 = 1
;   ...
;   2019: 50 or 51 => x/4 = 12
;   2020: 51 or 52 => x/4 = 12 or 13
;   2021: 52 or 53 => x/4 = 13
;   ...

; This is a division by 4. You can do it using two SHR 1
; instructions: "SHR register, 1"
leapyears = leapyears SHR 2

; Add the result to the number of days from 1970/1/1
; until today
time = time + leapyears

; Look up the number of days from 1/1 of this year until
; the 1st of this month; not including 2/29 (if any)
; You could do this the following way:
;    LEA BX, lookupTable
;    ADD BX, month (in a 16-bit register)
;    MOV AX, [BX]
; Or:
;    LEA BX, lookupTable
;    ADD BL, month (in an 8-bit register)
;    ADC BH, 0
;    MOV AX, [BX]
yearDays = lookupTable[month]

; And add this number to the number of days
time = time + yearDays

; Add the day-of-month to the number of days since 1970/1/1
time = time + dayOfMonth - 1

; Convert days to seconds (note: We assume: No leap seconds)
; and add hours, minutes and seconds (note: We assume: GMT time zone)
time = 24 * time
time = time + hours
time = 60 * time
time = time + minutes
time = 60 * time
time = time + seconds

---
lookupTable:
    0         # illegal
    0         # Days between 1/1 and 1/1
    31        # Days between 2/1 and 1/1
    31+28     # Days between 3/1 and 1/1
    31+28+31  # Days between 4/1 and 1/1
    ...

Я уверен, что вы сможете конвертировать псевдокод в ассемблер - если вам действительно нужно это сделать.

...