MASM Assembly Language x86 Processor - Random_Screen_Location (Chapter 5, Pr 7)
ID: 3591237 • Letter: M
Question
MASM Assembly Language x86 Processor -
Random_Screen_Location (Chapter 5, Pr 7)
Hello Chegg experts, this is one of my programming assignments for MASM assembly language x86 Processor.
I desperately need your help on this!! Also use Irvine32 library.
Here is the assignment:
DOS_file_time (Chapter 7, Supplied)
Suppose the time field of a file directory entry uses bits 0-4 for 2-second increments, bits 5-10 for minutes, and bits 11-15 for hours (24-hour clock). Write a procedure named ShowFileTime that receives a binary file time value in the AX register and displays the time in hh:mm:ss format. For example, the binary 0001 0010 0000 0111 indicates a time of 02:16:14, in hh:mm:ss format:
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:
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 digits.
-----------------
Thank you in advance...
00010 010000 00111DOS_file_time (Chapter 7, Supplied) upposa the time fiald of a file diractory entry uses bits 0-4 for 2-second incraments, bits 5-10 far minutes, and bits 11-15 for haurs (24-hour clack) Writa a procaclune namad ShowFilaTime that roceivas a binary fle time value in tha AX ragister and displays the time in hh mmss format. For example, the binary 0001 0010 0000 0111 indicates a time of 02:16 14, in hh:mm:ss fonmat 00010 010000 00111 For simplicity, we want ta input 4 digt hexadecimal and show i screen will be like this its binary to verify . For this, you can call ReadHex and WriteBinB. Then you can call your ShaowfileTime to display the file time. You may call WriteDec, WriteChar, and consider prefixed zeros. Run your program; the Please enter 16-bit hexadecinal (1-digit,e.g. 1207) A103 Yo r equivalent binary 1 101D DDD! DDDD 0011 Your DO8 fine tin i 20:08:06 " 20,08:06 0001 0000001112 P16dB"sents r 16-bit hezadBG inal 4-digit, ULU UDUU e.g., 1207): 1207 Any reusable helper proccdure is proferred, such as displaying a leading zera character if the value of haurs, minutes, ar seconds less than 1D, dlse displaying an ariginal twa digit Advanced discussion (not required A possible issue is display of invalid hours, minutes, and seconds. For a real wond app. you do need to check hours 0 to 23, mnutes 0 to 59, and seconds 0 to 59 from the the user input. Since purpoge of this is to practice shift and rotate instructions, you can simply ignore the erar chacking without caring about these 19p top
Explanation / Answer
TITLE DOS File Time (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
;
; Checks to see if a hex number fits DOS file time format
; Receives: EAX hex number to be analyzed
; Returns: sets zero flag if format is incorrect
;------------------------------------------------------------
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
; Receives: EAX time to be displayed
; Returns: nothing
;------------------------------------------------------------
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
; screen if it does
; Receives: ECX the number to be checked
; Returns: nothing
;------------------------------------------------------------
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.