MASM

Randomizing Numbers in Assembly with MASM32

允我心安 提交于 2019-11-27 09:06:33
问题 How can I randomize a number using Assembly with Masm32? What can I use to create a random numbers generator? Thank you very much! 回答1: 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

How to create nested loops in x86 assembly language

旧巷老猫 提交于 2019-11-27 08:44:12
问题 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; } } } 回答1: Sure, it's possible. Since every computer program eventually

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

試著忘記壹切 提交于 2019-11-27 08:08:42
问题 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:

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

我是研究僧i 提交于 2019-11-27 07:15:14
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . 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 回答1: As filofel says, use the Win32 API. Here's a small hello world example: .386 .MODEL flat, stdcall STD

Why does using “int 21h” on Assembly x86 MASM cause my program to crash?

不想你离开。 提交于 2019-11-27 04:55:27
问题 I was trying to make my program accept input without the user having to press enter, so I tried the following: mov ah,01h int 21h But it just crashes my program over an unhandled exception . This seems to be the way to do it according to much that I have read, so why isn't it working for me? Now, I am fairly new to this language so I still do not exactly understand the process of how this piece of code works, so I would also appreciate what the logic is behind accepting input by pressing

Printing Hexadecimal Digits with Assembly

ぃ、小莉子 提交于 2019-11-26 23:00:47
I'm trying to learn NASM assembly, but I seem to be struggling with what seems to simply in high level languages. All of the textbooks which I am using discuss using strings -- in fact, that seems to be one of their favorite things. Printing hello world, changing from uppercase to lowercase, etc. However, I'm trying to understand how to increment and print hexadecimal digits in NASM assembly and don't know how to proceed. For instance, if I want to print #1 - n in Hex, how would I do so without the use of C libraries (which all references I have been able to find use)? My main idea would be to

How do we clear the console in assembly?

有些话、适合烂在心里 提交于 2019-11-26 22:07:41
问题 I am looking for a win32 api function that clears the console, much like the cls command Thanks! Devjeet 回答1: This is pretty old, but should still work. Conversion to assembly language is left as an exercise for the reader, but shouldn't be terribly difficult (most of it is just function calls, and the multiplication is trivial): #include <windows.h> void clear_screen(char fill = ' ') { COORD tl = {0,0}; CONSOLE_SCREEN_BUFFER_INFO s; HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);

How to code a far absolute JMP/CALL instruction in MASM?

孤街浪徒 提交于 2019-11-26 18:37:35
问题 How can I write a far absolute JMP or CALL instruction using MASM? Specifically how do I get it to emit these instruction using the EA and CA opcodes, without manually emitting them using DB or other data directives? For example consider the case of jumping to the BIOS reset entry point at FFFF:0000 in a boot sector. If I were using NASM I could code this in one instruction in the obvious way: jmp 0xffff:0 With the GNU assembler the syntax is less obvious, but the following will do the job:

Confusing brackets in MASM32

泪湿孤枕 提交于 2019-11-26 17:51:43
I am trying to get to grips with MASM32 and am confused by the following: I thought that brackets were used for indirection so if I have the a pre-defined variable .data item dd 42 then mov ebx, item would put the contents of 'item', i.e. the number 42, into ebx and mov ebx, [item] would put the address of 'item', i.e. where the 42 is stored, into ebx. But the following code in a console app: mov ebx, item invoke dwtoa, ebx, ADDR valuestr invoke StdOut, ADDR valuestr mov ebx, [item] invoke dwtoa, ebx, ADDR valuestr invoke StdOut, ADDR valuestr prints 42 twice. To get the address of 'item' I

Illegal use of register in indirect addressing

北战南征 提交于 2019-11-26 17:24:50
问题 I'm trying to write a subroutine that adds two large numbers in x86 assembly (MASM). The numbers are pointed at by the si and di registers, and the function should iterate from right to left, adding each data word and passing the carry, and saving the result in di. The number of data words to add is determined by a previous chunk of code. ... mov cx, ( number of data words to add ) adding: mov bx,cx ;copy the loop counter to bx lea ax,[di+2*bx] ;move ax to the destination word adc ax,[si+2*bx