to DOS_ file_time (Chapter 7, Supplied) Suppose the time field of a file directo
ID: 3592538 • Letter: T
Question
to DOS_ file_time (Chapter 7, Supplied) Suppose the time field of a file directory entry uses bits 0-4 for 2 hours (24-hour clock). Write a procedure ShowFi displays the time in hh:mm:ss format. binary 0 hh:mm:ss format: -second increments, bits 5-10 for minutes, and bits 11-15 for e named ShowFileTime that receives a binary file time value in the AX register and t. For example, the binary 0001 0010 0000 0111 indicates a time of 02:16:14, in 00010 010000 0011 For simplicity, we want to input 4-digit hexadecimal and show its binary to verify. For this, you can call ReadHex and WriteBinB. Then you can call your ShowFileTime to display the file time. You may call WriteDec, WriteChar, and consider prefixed zeros. Run your program; the screen will be like this C:TeachingcscI241KipIrvineSixthEditionProg_Ex_SMch07Debug project Please enter 16-bit hexadecimal (4-digit, e.g., 1207): A103 Your equivalent binary is 1010 0001 0000 0011 Your Dos file time is 20:08:06 c:TeachingcscI241KipIrvineSixthEditionProg_Ex_ SMch07Debug project Please enter 16-bit hexadecimal (4-digit, e.g., 1207): 1207 Your equivalent binary is 0001 0010 0000 0111 Your DOS file time is 02:16:14 Any reusable helper procedure is preferred, such as displaying a leading zero character if the value of hours, minutes, or seconds less than 10, else displaying an original two digitsExplanation / Answer
DOS_File_Time.asm
INCLUDE Irvine32.inc
.data
prompt1 BYTE "Please enter 16-bit hexadecimal (4-digit, e.g., 1207): ",0
prompt2 BYTE "Your equivalent binary is ",0
prompt3 BYTE "Your DOS file time is ",0
prompt4 BYTE "Sorry, invalid entry...", 0dh, 0ah, 0dh, 0ah, 0
.code
DOS PROC
mov edx,OFFSET prompt1
call WriteString
call ReadHex
call CheckFormat ;check format before outputting anything else
jz Error ;ZF=0 if valid
mov edx,OFFSET prompt2
call WriteString
mov ebx,TYPE WORD
call WriteBinB
call crlf
mov edx,OFFSET prompt3
call WriteString
call ShowFileTime
call crlf
call crlf
exit
Error:
mov edx,OFFSET prompt4
call WriteString
exit
DOS ENDP
;------------------------------------------------------------
CheckFormat PROC USES eax
mov ecx,eax
cmp eax,65535
ja Set
and ax,001Fh
cmp ax,29
ja Set
mov eax,ecx
and ax,07D0h
cmp ax,1888
ja Set
mov eax,ecx
and ax,0F800h
cmp ax,49152
ja Set
ret
Set:
and ecx,0
ret
CheckFormat ENDP
;------------------------------------------------------------
ShowFileTime PROC
;
; Displays file time in proper format
mov ecx,eax
mov edx,eax
shr ecx,11
call LeadingZero
mov al,':'
call WriteChar
mov ecx,edx
shr cx,5
and cx,3Fh
call LeadingZero
mov al,':'
call WriteChar
mov ecx,edx
and ecx,001Fh
mov eax,ecx
mov bx,2
mul bx
mov ecx,eax
call LeadingZero
ret
ShowFileTime ENDP
;------------------------------------------------------------
LeadingZero PROC
;
; Check if a number needs a leading zero and write it to the
cmp ecx,9
ja L1
mov eax,0
call WriteDec
L1: mov eax,ecx
call WriteDec
ret
LeadingZero ENDP
END DOS
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.