3

Student here:

I would like a way to create a string holding the current date/time of the build, that I can output to the console. I have a consolOut that outputs strings character by character(string ending in a null), but I don't know how to actually use the @date @time macro that is listed in my book as a "Symbol" and outputting a string during assembly time.

If I put them in quotes it'll output '@date' with no change. If I don't put it in quotes it will not build.

Do I somehow call them at runtime then store them in .data with a mov? how would I even interact with them, they seem bigger than my eax?

(This isn't required on my homework- I just like having nice headers.)

NULL EQU 0  ;constants(ascii): null == 0
LF EQU 0Ah  ;linefeed == LF
CR EQU 0Dh  ;carrage return == CR


printHEADER PROC
    .data
        header  byte    '<myname> CS 340 ASSEMBLY '
                byte    @date, ' '
                byte    @time
                byte    LF, CR, NULL
    .code
        lea esi, header
        call consolOut             ;arguments: esi as string ending in 0
        ret
printHEADER endP
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Silver
  • 33
  • 3

1 Answers1

4

It's possible that something already exists for handling this in MASM itself or one of MASM32's libraries. But I couldn't find it, so I put together a simple solution of my own:

include \masm32\include\masm32rt.inc

NULL EQU 0  ;constants(ascii): null == 0
LF EQU 0Ah  ;linefeed == LF
CR EQU 0Dh  ;carrage return == CR

; Stringifies a text macro.
; Expands into a quoted expansion of arg.
stringify MACRO arg
    LOCAL foo
    foo CATSTR <'>,arg,<'>
    EXITM foo
ENDM


.data
header  byte '<myname> CS 340 ASSEMBLY '
        byte stringify(@Date), ' '
        byte stringify(@Time)
        byte CR, LF, NULL

.code
start:
    printf("%s", OFFSET header)
    invoke ExitProcess,0
end start
Michael
  • 57,169
  • 9
  • 80
  • 125