Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write and submit a MARS MIPS Assembly Language program which requests an integer

ID: 3759275 • Letter: W

Question

Write and submit a MARS MIPS Assembly Language program which requests an integer (year) from the user and then invokes a function to determine the beginning date and time of each season. The program must be properly documented which includes in file comments. Note: This is a Computer Science/Engineering course, not a Physics/Astronomy course. The exact time is not expected. Approximations are acceptable. Document your calculation process in the report. Basically, the intent is that you store a reference date and time for each Equinox and Solstice. Then, multiply the difference in years by 365 days, 5 hours, and 50 minutes to determine the date and time for the requested year. Suppose that you use 2015 as the reference year. Then it is known that spring began at 5:46 P.M. on March 20 (Julian Date 79). If you want to know when spring begins in 2018, then you would add 1095 days, 15 hours, and 150 minutes and subtract the number of days in 2015, 2016, and 2017 (365, 366, 365). 79(17:46)+1,095(17:30)-1096 = 78(35:16) = 79(11:16) That gives you 11:16 A.M. on March 20 in 2018 which matches the actual date and time.

Explanation / Answer

; Source name : TIMETEST.ASM

; Executable name : TIMETEST

; nasm -f elf -g -F stabs timetest.asm

; gcc timetest.o -o timetest

;

[SECTION .data] ; Section containing initialised data

TimeMsg db “Hey, what time is it? It’s %s“,10,0

YrMsg db “The year is %d.“,10,0

Elapsed db “A total of %d seconds has elapsed since program began running.“,

10,0

[SECTION .bss] ; Section containing uninitialized data

OldTime resd 1 ; Reserve 3 integers (doubles) for time values

NewTime resd 1 ; 32-bit time_t value

TimeDiff resd 1 ; 32-bit time_t value

TimeStr resb 40 ; Reserve 40 bytes for time string

TmCopy resd 9 ; Reserve 9 integer fields for time struct tm

[SECTION .text] ; Section containing code

extern ctime

extern difftime

extern getchar

extern printf

extern localtime

extern strftime

extern time

global main ; Required so linker can find entry point

main:

push ebp ; Set up stack frame for debugger

mov ebp,esp

push ebx ; Program must preserve EBP, EBX, ESI, & EDI

push esi

push edi

;;; Everything before this is boilerplate; use it for all ordinary apps!

; Generate a time_t calendar time value with glibc’s time() function:

push 0 ; Push a 32-bit null pointer to stack,

; since we don’t need a buffer.

call time ; Returns calendar time in EAX

add esp,4 ; Clean up stack after call

mov [OldTime],eax ; Save time value in memory variable

; Generate a string summary of local time with glibc’s ctime() function:

push OldTime ; Push address of calendar time value

call ctime ; Returns pointer to ASCII time string in EAX

add esp,4 ; Stack cleanup for 1 parm

push eax ; Push pointer to ASCII time string on stack

push TimeMsg ; Push pointer to base message text string

call printf ; Merge and display the two strings

add esp,8 ; Stack cleanup: 2 parms X 4 bytes = 8

; Generate local time values into glibc’s static tm struct:

push dword OldTime ; Push address of calendar time value

call localtime ; Returns pointer to static time structure in

EAX

add esp,4 ; Stack cleanup for 1 parm

; Make a local copy of glibc’s static tm struct:

mov esi,eax ; Copy address of static tm from eax to ESI

mov edi,TmCopy ; Put the address of the local tm copy in EDI

mov ecx,9 ; A tm struct is 9 dwords in size under Linux

cld ; Clear DF so we move up-memory

rep movsd ; Copy static tm struct to local copy

; Display one of the fields in the tm structure:

mov edx,dword [TmCopy+20] ; Year field is 20 bytes offset into tm

add edx,1900 ; Year field is # of years since 1900

push edx ; Push value onto the stack

push YrMsg ; Push address of the base string

call printf ; Display string and year value with printf

add esp,8 ; Stack cleanup: 2 parms X 4 bytes = 8

; Wait a few seconds for user to press Enter so we have a time difference:

call getchar ; Wait for user to press Enter

; Calculating seconds passed since program began running:

push dword 0 ; Push null ptr; we’ll take value in EAX

call time ; Get current time value; return in EAX

add esp,4 ; Clean up the stack

mov [NewTime],eax ; Save new time value

sub eax,[OldTime] ; Calculate time difference value

mov [TimeDiff],eax ; Save time difference value

push dword [TimeDiff] ; Push difference in seconds onto the stack

push Elapsed ; Push addr. of elapsed time message string

call printf ; Display elapsed time

add esp,8 ; Stack cleanup for 1 parm

;;; Everything after this is boilerplate; use it for all ordinary apps!

pop edi ; Restore saved registers

pop esi

pop ebx

mov esp,ebp ; Destroy stack frame before returning

pop ebp

ret ; Return control to Linux

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote