This commit is contained in:
ergz 2022-06-22 23:29:35 -07:00
parent 13cbecb0e9
commit 587de74b26
14 changed files with 114 additions and 4 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*.ilk
*.pdb
*.obj
*sublime-workspace

BIN
a.exe Normal file

Binary file not shown.

View File

@ -0,0 +1,8 @@
{
"folders":
[
{
"path": "."
}
]
}

BIN
mllink$.lnk Normal file

Binary file not shown.

BIN
program.exe Normal file

Binary file not shown.

View File

@ -17,3 +17,45 @@ fmt_string byte "User entered: '%s'", nl, 0
input byte maxlen dup (?)
.code
externdef printf:proc
externdef readline:proc
public get_title
; procedure loads the address of the title_str into the RAX
; register, this is the register where C expects to find
; the return of this proc. (WINDOWS ABI)
get_title proc
lea rax, title_str ; load address of title string in RAX register
ret
get_title endp
; ASM Main function
public asm_main
asm_main proc
sub rsp, 56
lea rcx, prompt ; load prompt string address into RCX register
call printf ; this is the reigster where ABI tells us to place arguments
mov input, 0 ; ensure the input string is terminated with 0
lea rcx, input ; load input address to rcx register
mov rdx, maxlen ; move maxlen into rdx register
call readline ; use rcx and rdx as arguments to call readline
lea rcx, fmt_string
lea rdx, input
call printf
add rsp, 56
ret
asm_main endp
end

BIN
src/1_8.exe Normal file

Binary file not shown.

52
src/2_2.asm Normal file
View File

@ -0,0 +1,52 @@
option casemap:none
nl = 10
.data
left_op dword 0f0f0f0fh
right_op1 dword 0f0f0f0f0h
right_op2 dword 12345678h
title_str byte "Listing 2-2", 0
fmt_str1 byte "%lx AND %lx = %lx", nl, 0
fmt_str2 byte "%lx OR %lx = %lx", nl, 0
fmt_str3 byte "%lx XOR %lx = %lx", nl, 0
fmt_str4 byte "%NOT lx = %lx", nl, 0
.code
externdef printf:proc
public get_title
get_title PROC
lea rax, title_str ; load title string address into rax register
ret
get_title ENDP
public asm_main
asm_main PROC
sub rsp, 56
; AND operator
lea rcx, fmt_str1 ; load fmt str address
mov edx, left_op
mov r8d, right_op1
mov r9d, edx
and r9d, r8d
call printf
lea rcx, fmt_str1
mov edx, left_op
mov r8d, right_op2
mov r9d, r8d
and r9d, edx
call printf
asm_main ENDP
END

BIN
src/2_2.exe Normal file

Binary file not shown.

BIN
src/a.exe Normal file

Binary file not shown.

4
src/build.bat Normal file
View File

@ -0,0 +1,4 @@
@echo off
echo ~~~~ starting build ~~~~
ml64 /nologo /c /Zi /Cp %1.asm
cl /nologo /O2 /Zi /utf-8 /EHa /Fe%1.exe c.cpp %1.obj

View File

@ -17,7 +17,7 @@ extern "C"
int readline(char *dest, int maxlen)
{
char *result = fgets(dest, maxlen, stdin);
if (results != NULL) {
if (result != NULL) {
int len = strlen(result);
if (len > 0) {
dest[len - 1] = 0;
@ -25,7 +25,7 @@ int readline(char *dest, int maxlen)
return(len);
}
return(-1) // an error occured
return(-1); // an error occured
}
int main(void)
@ -34,10 +34,10 @@ int main(void)
try {
char *title = get_title();
printf("calling %s\n", title);
asm_func();
asm_main();
printf("%s terminated\n", title);
} catch(...) {
printf("an error occured!")
printf("an error occured!");
}
}

BIN
src/c.exe Normal file

Binary file not shown.

BIN
src/main.exe Normal file

Binary file not shown.