MASM

Randomizing Numbers in Assembly with MASM32

一个人想着一个人 提交于 2019-11-28 14:52:52
How can I randomize a number using Assembly with Masm32? What can I use to create a random numbers generator? Thank you very much! Get random numbers with MASM32 The MASM32 SDK comes with some examples which implement random generators. It isn't the worst idea to use them for own purposes. The following examples are just examples and lack - among others - in an error handling. The examples generate and produce 30 random numbers in the range [0..11]. A linear congruential generator with a=134775813 and b=c (like Delphi) is in \masm32\examples\exampl03\lcd\lcd.asm . .686 .MODEL flat, STDCALL

How to create nested loops in x86 assembly language

a 夏天 提交于 2019-11-28 14:38:41
Is it possible to create nested loops in x86 assembly language? I'd like to translate this psedocode into correct x86 assembly code (using MASM syntax), but I'm not sure how to initialize each loop counter here. Is it even possible to declare local variables in x86 assembly (as in most other programming languages)? for (var i = 0; i < 10; i++){ for(var j = 0; j < 10; j++){ for(var k = 0; k < 10; k++){ mov eax, i + j + k; } } } Sure, it's possible. Since every computer program eventually boils down to assembly - it is naturally the most powerful language possible (excluding direct bit

How to write an absolute target for a near direct relative call/jmp in MASM

谁都会走 提交于 2019-11-28 13:50:22
To make a normal (near direct relative) call to an absolute address, in NASM or AT&T syntax you write call 0x1234567 , and the assembler + linker take care of calculating a rel32 to reach that target from wherever the linker puts the call instruction. e.g. on Linux assembling that into a static 64-bit ELF executable with yasm -felf64 foo.asm && ld foo.o -o foo , then disassembled with objdump -drwC -Mintel foo gives you: foo: file format elf64-x86-64 Disassembly of section .text: 0000000000400080 <_start>: 400080: e8 e2 44 e3 00 call 1234567 <_end+0xc344df> The linker calculated the right

How can I do Input/Output on a console with MASM? [closed]

谁说胖子不能爱 提交于 2019-11-28 12:49:44
I've googled and googled, and I've not found anything useful. How can I send output to the console, and accept user input from the console with assembly? I'm using MASM32 As filofel says, use the Win32 API. Here's a small hello world example: .386 .MODEL flat, stdcall STD_OUTPUT_HANDLE EQU -11 GetStdHandle PROTO, nStdHandle: DWORD WriteConsoleA PROTO, handle: DWORD, lpBuffer:PTR BYTE, nNumberOfBytesToWrite:DWORD, lpNumberOfBytesWritten:PTR DWORD, lpReserved:DWORD ExitProcess PROTO, dwExitCode: DWORD .data consoleOutHandle dd ? bytesWritten dd ? message db "Hello World",13,10 lmessage dd 13

x86 assembly (masm32) - Can I use int 21h on windows xp to print things?

こ雲淡風輕ζ 提交于 2019-11-28 11:45:10
问题 Just wondering, in regards to my post Alternatives to built-in Macros , is it possible to avoid using the StdOut macro by using the int 21h windows API? Such as: .data msg dd 'This will be displayed' ;original macro usage: invoke StdOut, addr msg ;what I want to know will work push msg int 21h ; If this does what I think it does, it should print msg Does such a thing exist (as in using int 21h to print things), or does something like it exist, but not exactly int 21h. Or am I completely wrong

Why do I have to play with “rsp” to call a c++ function?

人走茶凉 提交于 2019-11-28 09:06:18
问题 I just started my assembly journey like recently, so obviously I'm a newbie, I've been writing fairly simple and basic programs and I just noticed something weird (to me). a program giving the count of numbers in a table ending with 111 in binary entry point: #include <iostream> #include <cstdlib> extern "C" auto _start(void *, void *)->void; auto print_msg(char *msg) { std::cout << msg; } auto print_int(uint64_t val) { std::cout << val; } auto main()->int { _start(print_int, print_msg); std:

How to populate a 64 bit register with duplicate byte values

非 Y 不嫁゛ 提交于 2019-11-28 08:02:22
问题 I'm doing some x64 assembly with Visual C++ 2010 and masm ('fast call' calling convention). So let's say I have a function in C++: extern "C" void fillArray(unsigned char* byteArray, unsigned char value); The pointer to array will be in RCX and char value will be in DL How can I fill RAX with values using DL such that if I were to mov qword ptr [RCX], RAX and print byteArray, all the values would be equal to 'char value'? Please note that I'm not trying to do out-code my compiler, I'm just

A2004 Problem With MASM32

烈酒焚心 提交于 2019-11-28 06:38:17
问题 I have a problem with the MASM32 assembler The following code is a Hello World example that I copied from the MASM32 tutorial: .model small .stack .data message db "Hello world!", "$" .code _main proc mov ax,seg message mov ds,ax mov ah,09 lea dx,message int 21h mov ax,4c00h int 21h _main endp end _main On attempt to assemble, MASM32 throws A2004 error with the following comment: C:\masm32\console.asm(11) : error A2004: symbol type conflict Can anyone help me with that? This code worked

How are dw and dd different from db directives for strings?

左心房为你撑大大i 提交于 2019-11-28 06:26:32
问题 Let's say I want to define a initialized variable string before running my assembly program (in section .data ). The variable I chose to create is called Digits and it is a string that contains all the hexadecimal symbols. Digits: db "0123456789ABCDEF" I defined the variable with db , that means define byte . Does this mean that the Digits variable is of 8-bits long? This doesn't seem to have sense for me because: Each character in the string is an ASCII character, therefore I will need 2

Reverse byte order of EAX register

﹥>﹥吖頭↗ 提交于 2019-11-28 05:16:55
问题 Example: 0xAABBCCDD will turn into 0xDDCCBBAA My program crashes, due to Access Violation exception right in the first XOR operation. It seems like there's a better naive solution, using shifting or rotating, but anyways, here's the code: ;; ######################################################################### .486 .model flat, stdcall option casemap :none ; case sensitive ;; ######################################################################### include \masm32\include\masm32.inc