Log in

View Full Version : Confused with the following asm code


vhon1999
December 31st, 2009, 16:51
Hello I am new to reversing and in the process of learning by playing with stuff. As part of my learning process I am trying to go through code and enter comments and or go through code samples that have a already been comment. I am having trouble understanding the following comment asm. I am trying to figure out what it's doing and how the code if in anyway using the system clock/system time to do anything? Any help would be greatly appreciated.



seg000:00FA loc_FA: ; CODE XREF: start+B1j
seg000:00FA ; start+B8j ...
seg000:00FA mov ah, 0
seg000:00FC int 1Ah ; CLOCK - GET TIME OF DAY
seg000:00FC ; Return: CXX = clock count
seg000:00FC ; AL = 00h if clock was read or written (via AH=0,1) since the previous
seg000:00FC ; midnight
seg000:00FC ; Otherwise, AL > 0
seg000:00FE mov word_64951, dx
seg000:0102 mov word_64953, cx
seg000:0106 or al, al
seg000:0108 jz short loc_116
seg000:010A mov ax, 40h ; '@'
seg000:010D mov es, ax
seg000:010F assume es:nothing
seg000:010F mov bx, 70h ; 'p'
seg000:0112 mov byte ptr es:[bx], 1

Kayaker
December 31st, 2009, 17:52
Hi,

From another example of that code:

Code:

mov ah, 0
int 1ah ; get current BIOS time in ticks
mov word ptr __StartTime,dx ; save it for clock() fn
mov word ptr __StartTime+2,cx
or al,al ; was midnight flag set?
jz @@NotMidnight
mov ax,40h ; set BIOS midnight flag
mov es,ax ; at 40:70
mov bx,70h
mov byte ptr es:[bx],1
@@NotMidnight:


If you google around for 'INT 1A Read system clock counter' you'll find futher details.

This document
http://www.kryslix.com/nsfaq/Q.5.html
explains that

BIOS Low-Memory Data Area (0040:0000) is at segment 40h, and offset 70h is:
70h BYTE Timer overflow, non-zero if has counted past midnight


Also see the google cache of this document:

TN839C.txt How does DOS update the Date at Midnight ?

http://ckw.phys.ncku.edu.tw/public/pub/src/HTML/Languages/Cpp/BCppTechInfo/15839.html

http://74.125.93.132/search?q=cache:ieuf5RdHR5kJ:ckw.phys.ncku.edu.tw/public/pub/src/HTML/Languages/Cpp/BCppTechInfo/15839.html



You can often google for distinctive code instructions, such as "mov byte ptr es:[bx],1", which is what I did here, to get more info, then continue googling on clues obtained until you get a full explanation.

You've got the right learning attitude anyway