MASM

What is PC-relative addressing and how can I use it in MASM?

早过忘川 提交于 2019-12-10 18:03:02
问题 I'm following Jack Crenshaw's compiler tutorial (If you look at my profile, that's what all my questions are about lol) and it just got to the point where variables are introduced. He comments that the 68k requires everything to be "position-independent" which means it's "PC-relative". I get that PC is the program counter, and on x86 it's EIP. But he uses syntax like MOVE X(PC),D0 where X is a variable name. I've read a little ahead and it says nothing later about declaring a variable in

Generating random numbers in assembly

∥☆過路亽.° 提交于 2019-12-10 16:12:28
问题 I am new to assembly, and I am having problems generating random numbers. My code is simple: it generates 100 numbers in the 0-25 range and stores them in an array. The problem I am experiencing is that when I run the con on the emu8086 assembler it runs successfully and generates 100 random numbers, that are stored in the array. But when I run it on the masm611 , it generates a new random number every 4 cycles. Which means the values in the array are consecutive same number for 4 values and

Generic MASM code: storing 8 or 16 bits of a register depending on TYPE of a symbol

徘徊边缘 提交于 2019-12-10 15:15:36
问题 I am trying to write an array-reversing function that works correctly whether the static array holds BYTE s or WORD s. This is what I have so far where I assumed the array was of size WORD .data myArray WORD 1231h, 2342h, 3353h, 4564h, 5675h, 7, 9 .code main proc mov eax, 0 ;index of the left side of the array mov esi, SIZEOF myArray sub esi, TYPE myArray ;index of the right side of the array Switch: movsx edx, [myArray + eax] ;puts the left element of the array in eax xchg dx, [myArray + esi

How does ASM knows an arithmetic operation is signed or unsigned?

时光总嘲笑我的痴心妄想 提交于 2019-12-10 14:17:30
问题 I am assembling using MASM 14.0, and i am confused with the output of the below code. TITLE Exercise 4 from chapter 4 ; Author : Saad Ahmed INCLUDE Irvine32.inc .code main PROC mov eax, 0 mov al, 255 add al, 1 call DumpRegs ; Display registers mov al, 127 add al, 1 call DumpRegs ; Display registers exit main ENDP END main Both arithmetic operations are done on unsigned integers 255 and 127. However, the CPU is treating the first operation 255, as an unsigned integers and setting the carry

x86 assembly equ vs =

偶尔善良 提交于 2019-12-10 13:37:28
问题 I am taking a class in x86 assembly language and it's starting to move rather fast. There is one thing that the book keeps doing without mentioning how it works, and that is using the equ and = operators when defining data. So it seems like equ is used to define constants, but is = the same thing? If I had some code: .data count = 100 ; Is this a constant? Of what data type is this? array WORD count DUP(?) x_param EQU [EBP + 8] ; Is this a constant? I am asking because until now we have

mov ax, bx vs. mov ax, [bx]

泪湿孤枕 提交于 2019-12-10 06:28:15
问题 What is the difference between the following two lines? mov ax, bx mov ax, [bx] If bx contains the value 100h and the value at memory address 100h is 23, does the second one copy 23 to ax ? Also, what is the difference between the two following lines? mov ax, 102h ; moves value of 102h into register ax mov ax, [102h] ; Actual address is DS:0 + 102h 回答1: Yes. The operand between the brackets is treated as an address and the value at that memory address if fetched. 来源: https://stackoverflow.com

passing arrays to functions in x86 asm

北城余情 提交于 2019-12-09 23:41:09
问题 I'm learning x86 asm and using masm, and am trying to write a function which has the equivalent signature to the following c function: void func(double a[], double b[], double c[], int len); I'm not sure how to implement it? The asm file will be compiled into a win32 DLL. So that I can understand how to do this, can someone please translate this very simple function into asm for me: void func(double a[], double b[], double c[], int len) { // a, b, and c have the same length, given by len for

error LNK2001: unresolved external symbol _MessageBox

空扰寡人 提交于 2019-12-09 05:19:02
问题 I am trying to create a helloworld program using only masm and not masm32 libs. Here is the code snippet: .386 .model flat, stdcall option casemap :none extrn MessageBox : PROC extrn ExitProcess : PROC .data HelloWorld db "Hello There!", 0 .code start: lea eax, HelloWorld mov ebx, 0 push ebx push eax push eax push ebx call MessageBox push ebx call ExitProcess end start I am able to assemble this using masm: c:\masm32\code>ml /c /coff demo.asm Microsoft (R) Macro Assembler Version 9.00.21022

x86 assembly (MASM) - Square root of a 64-bit integer?

只谈情不闲聊 提交于 2019-12-09 01:54:14
问题 I'm coding a simple primality tester program for Windows in x86 assembly language (MASM32), which involves calculating a square root of a (64-bit) integer. My question is: Is there any simple way for obtaining the square root? Should I use some combination of ADD/SUB/DIV/MUL instructions? I found some information on how this could be achieved in C language, but I'm just wondering if I'm missing something here? 回答1: I think the simplest way is to use the FPU instruction fsqrt like this: .data?

Difference between lea and offset

你说的曾经没有我的故事 提交于 2019-12-08 15:17:02
问题 ar db "Defference $" What's the difference between mov dx,offset ar and lea dx,ar I think both are doing same work, but what is the difference between these two 回答1: In this use-case LEA and MOV do the same thing. LEA is more powerful than MOV if you want to calculate an address in a more complex way. Lets for example say you want to get the address of the n'th character in your array, and the n is stored in bx. With MOV you have to write the following two instructions: Mov dx, offset ar add