diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..84f8207 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.ilk +*.pdb +*.obj +*sublime-workspace diff --git a/a.exe b/a.exe new file mode 100644 index 0000000..b8ab5ad Binary files /dev/null and b/a.exe differ diff --git a/art-of-masm.sublime-project b/art-of-masm.sublime-project new file mode 100644 index 0000000..24db303 --- /dev/null +++ b/art-of-masm.sublime-project @@ -0,0 +1,8 @@ +{ + "folders": + [ + { + "path": "." + } + ] +} diff --git a/mllink$.lnk b/mllink$.lnk new file mode 100644 index 0000000..277c16e Binary files /dev/null and b/mllink$.lnk differ diff --git a/program.exe b/program.exe new file mode 100644 index 0000000..11ef19a Binary files /dev/null and b/program.exe differ diff --git a/src/1_8.asm b/src/1_8.asm index 02a726a..df3f986 100644 --- a/src/1_8.asm +++ b/src/1_8.asm @@ -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 diff --git a/src/1_8.exe b/src/1_8.exe new file mode 100644 index 0000000..6da200f Binary files /dev/null and b/src/1_8.exe differ diff --git a/src/2_2.asm b/src/2_2.asm new file mode 100644 index 0000000..b99031d --- /dev/null +++ b/src/2_2.asm @@ -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 + \ No newline at end of file diff --git a/src/2_2.exe b/src/2_2.exe new file mode 100644 index 0000000..4fe6960 Binary files /dev/null and b/src/2_2.exe differ diff --git a/src/a.exe b/src/a.exe new file mode 100644 index 0000000..2027a59 Binary files /dev/null and b/src/a.exe differ diff --git a/src/build.bat b/src/build.bat new file mode 100644 index 0000000..f618919 --- /dev/null +++ b/src/build.bat @@ -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 \ No newline at end of file diff --git a/src/c.cpp b/src/c.cpp index fed16fc..f2c8219 100644 --- a/src/c.cpp +++ b/src/c.cpp @@ -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!"); } } \ No newline at end of file diff --git a/src/c.exe b/src/c.exe new file mode 100644 index 0000000..69fbe55 Binary files /dev/null and b/src/c.exe differ diff --git a/src/main.exe b/src/main.exe new file mode 100644 index 0000000..ff065a3 Binary files /dev/null and b/src/main.exe differ