Loading...
More Plaintext Posts
##README: Rename file to "data" (no extension) and delete this line4 4.555 5.706 6.807 7.958 9.109 10.2010 11.3511 12.5012 13.6013 14.7514 15.9015 1716 18.1517 19.3018 20.4019 21.5520 22.7021 23.8022 24.9523 26.1024 27.2525 27.8026 28.9527 30.1028 31.2029 32.3530 33.5035 39.1540 44.8045 50.5050 55.6060 6770 78.3075 83.4580 89.1090 100.45100 111.25125 139150 166.85200 222.50
; Sample project from the video "Setup Visual Studio for Assembly MASM" https://www.youtube.com/watch?v=LqyVybUodXE; Basically reverses a string using the stack. It stores the result where the string was defined, modifying the string itself in memory..386;x86 instruction set. This is only nessesary in x32 MASM..model flat, stdcall;Defines the memory model, and the calling convention http://masm32.com/board/index.php?topic=6942.msg74381#msg74381.stack 4096;Sets the size of the stack. 4096 is 1024*4 which is 4 kilobytes.;option casemap:none;Make labels case sensitive, so things like ExitProcess and exitprocess and myName and myname are different.;include \masm32\include\windows.inc;include \masm32\include\kernel32.inc;includelib \masm32\lib\kernel32.lib;Some system calls or something are defined here. Not needed if you just use assembly along side c++ or c. Also can't be used if on anything other than windows.ExitProcess PROTO, dwEXITCODE:DWORD;Define the ExitProcess function prototype. ExitProcess is defined somewhere in the Windows API on the OS level..data;Starts the data section of the program, where a lot of read-write memory is neededmyName BYTE "Leif Messinger", 0;Allocates a string named myName initialized with LeifMessinger followed by a terminating null charactermyNameLength = ($ - myName) - 1;Allocates a 32 bit number which is initialized to be the current pointer ($), minus the pointer to the start of the string, minus one (because of the null terminating character).code;Starts the section of the program where your code goes. Is the same as .text, and in theory, the name doesn't even matter. The importance is that it ends the data section, which was read-write. Code should be read only.main PROC;States the start of the main procedure. This is where the program starts executing.mov ecx, myNameLength;Sets the loop counter to myNameLength. The loop counts backwards until it reaches zero, meaning that it loops myNameLength times.mov esi, 0;Sets the general purpose register esi to 0. esi was named because it's a "source index" when moving stuff. It's basically like an i variable in c.StackIt:;Flag to the start of the loop. Ahh, tss push itmovzx eax, myName[esi];movzx stands for move with zero extend. It pads the source data (myName[esi]) with enough zeros to fill 32 bits, or enough for the push and pop instructions.push eax;Pushes the character we just got out of that string (and padded with zeros) to the stackinc esi;Increments our indexloop StackIt;Decrements ecx and checks if it is equal to 0. If it isn't, jump to StackItmov ecx, myNameLength;Sets the loop counter to myNameLength. The loop counts backwards until it reaches zero, meaning that it loops myNameLength times.mov esi, 0;Sets the general purpose register esi to 0. esi was named because it's a "source index" when moving stuff. It's basically like an i variable in c.PopIt:;Flag to the start of the loop.pop eax;Pops a 32 bit number off the stack and places it in eaxmov myName[esi], al;Move the lower byte of eax (al) to the string (myName) at the index esi. This overwrites one character of the string.inc esi;Increments our indexloop PopIt;Decrements ecx and checks if it is equal to 0. If it isn't, jump to StackItINVOKE ExitProcess, 0;Exits the program with the error code of 0. The return type was declared in that prototype at the top, and defined by the operating systemmain ENDP;States the end of the main procedureEND main;Declares the end of the file. Also defines where the start of the program is, which is main.;Normally the linker looks for main as a place to start, but if you are writing pure assembly, that is need.;Saying END without a pointer to the start is also alowed for people who like to live dangerously.
# This is the network config written by 'subiquity'network:ethernets:enp0s3:dhcp4: yesnameservers:addresses: [8.8.8.8,8.8.4.4]version: 2
aaaa
;Main.asm.386.model small,c ;This bit is important, I think..stack 1000h.datahello db "Hello world!",0.code;includelib libucrt.lib ;All this shit is already here if you have a C object fileincludelib legacy_stdio_definitions.lib ;Except for this. Basically printf, puts etc;includelib libcmt.lib;includelib libvcruntime.lib ;Visual Studio exception handling and type checking. Not needed otherwiseextrn printf:near ;Extern everything you are gonna use from the c obj filesextrn plusTwo:nearextrn exit:nearpublic plusOne ;Have to declare it public for the linker to see it. In NASM, it's .globl or globalplusOne proc ;Our int plusOne(int) function.pop eax ;Parameters are stored on the stack.add eax, 1ret ;eax is whatever is returned from functions. Also why you can only return one thing.plusOne endppublic mainmain procpush offset hellocall printfpush 1call plusTwopush 0call exitmain endpend ;End of file, not program//bruh.c//#include <stdio.h> Has to be included with "includelib legacy_stdio_definitions.lib" in the asm file for some reason.//int printf(const char* format, ...);extern int plusOne(int); //Extern everything you are gonna use from the asm obj filesint plusTwo(int num) {return plusOne(plusOne(num)); //Plus one is defined in the assembly.}
alert('123');