How can I get the current UNIX time on 8086 asm? I couldn't find any information on the internet. I know it's 32bit so it would have to fill 2 registers. EDIT: OS is DOS(I'm using Dosbox)
How can I get the current ... time on 8086 asm?
The question is: "What operating system are you using?"
A CPU does not have any kind of real-time clock. And even early x86 PCs did not have one. The operating system (or the BIOS) knows how to get the system time.
How can I get the current UNIX time on 8086 asm?
If your operating system does not support the UNIX time but it supports the time given as "date" (Y,M,D,h,m,s), there is only the hard way:
Here the pseudo-code:
; 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
...
I'm sure you'll be able to convert the pseudo-code to assembler - if you really need to do this.