NSWI170 Computer Systems

Example: Assembler

#include "display.h"

const char* message = "Hello world\n";

int main()
{
    show(message);
    return 0;
}

CL /FA output.asm hello.cpp

; Listing generated by Microsoft (R) Optimizing Compiler Version 19.35.32215.0 

include listing.inc

INCLUDELIB LIBCMT
INCLUDELIB OLDNAMES

PUBLIC  ?message@@3PEBDEB               ; message
CONST   SEGMENT
$SG2779 DB  'Hello world', 0aH, 00H
CONST   ENDS
_DATA   SEGMENT
?message@@3PEBDEB DQ FLAT:$SG2779           ; message
_DATA   ENDS
PUBLIC  main
EXTRN   ?show@@YAXPEBD@Z:PROC               ; show
pdata   SEGMENT
$pdata$main DD  imagerel $LN3
    DD  imagerel $LN3+23
    DD  imagerel $unwind$main
pdata   ENDS
xdata   SEGMENT
$unwind$main DD 010401H
    DD  04204H
xdata   ENDS
; Function compile flags: /Odtp
_TEXT   SEGMENT
main    PROC
; File hello.cpp
; Line 6
$LN3:
    sub rsp, 40                 ; 00000028H
; Line 7
    mov rcx, QWORD PTR ?message@@3PEBDEB    ; message
    call    ?show@@YAXPEBD@Z            ; show
; Line 8
    xor eax, eax
; Line 9
    add rsp, 40                 ; 00000028H
    ret 0
main    ENDP
_TEXT   ENDS
END