MASM

Get structure size within MASM

情到浓时终转凉″ 提交于 2019-12-12 04:36:47
问题 I am wondering how to get the size of a structure at compilation time in MASM. Here is the C equivalent code. struct Point { int x; int y; }; printf("Point Stucture size %d\n", sizeof(struct Point)); 回答1: I'm assuming that you'll be declaring the struct in your assembly code. According to the masm32 documentation you've got the following operators available to you: LENGTHOF variable SIZEOF variable SIZEOF type LENGTH expression SIZE expression Description The LENGTHOF operator returns the

How do I know whether MASM encodes my JMP instruction using a relative or absolute offset?

感情迁移 提交于 2019-12-12 04:20:56
问题 How do I know whether MASM encodes my JMP instruction using a relative or absolute offset? I know that x86 provides JMP opcodes for relative and absolute offsets. I want to be certain that my jumps are relative, however I cannot find any proper MASM documentation telling me whether JMP @label actually translates into a relative jump. Please, if possible, give a link to documentation in the answer. For the opposite issue: See How to code a far absolute JMP/CALL instruction in MASM? if you're

Assembly write number to file

痞子三分冷 提交于 2019-12-12 03:23:23
问题 I try to write number to file via Assembler Include Irvine32.inc .data fileName DB 'number.txt',0 FileHandle DD ? numberBytes DD ? number DD 101 numberChar DD $-cislo .code WriteToFileP proc ;create file push NULL push FILE_ATTRIBUTE_NORMAL push CREATE_ALWAYS push NULL push 0 push GENERIC_WRITE push offset fileName call CreateFileA mov FileHandle,eax ;write push NULL push offset numberBytes push numberChar push number push FileHandle call WriteFile ; close file push FileHandle call

“invalid instruction operands” on mov ah, word_variable, and using imul on 16-bit numbers

Deadly 提交于 2019-12-12 02:44:34
问题 Here is what I am trying to achieve: a_x*b_x + a_y*b_y + a_z*b_z I am trying to make a MACRO in assembly that does the above computation. I am using WORD s for all of my numbers. Here is my code: dotProduct MACRO A_X,A_Y,A_Z,B_X,B_Y,B_Z ;a.b (a dot b) = a_x*b_x + a_y*b_y + a_z*b_z mov ah, A_X mov al, B_X imul ax mov answer, ax mov ah, A_Y mov al, B_Y imul ax add answer, ax mov ah, A_Z mov al, B_Z imul ax mov answer, ax output answer ENDM answer BYTE 40 DUP (0) But I am getting the following

Trouble when reverse and display string in assembly

时间秒杀一切 提交于 2019-12-12 02:44:00
问题 here is my code: model small stack 100h .data string1 db "Khoa$" string2 db 4 dup(?) count dw 4 .code begin: mov ax,@data mov ds,ax mov es,ax mov cx,count mov si,0 mov di,0 add di,count dec di again: mov al,string1[si] mov string2[di],al inc si dec di loop again mov ah,9 lea dx,string1 int 21h end begin in this part mov ah,9 lea dx,string1 int 21h when i try to display string1 to console, it's ok. but no result with string2. i'm new to assembly. Please help! 回答1: Although this is homework,

Executing segment codes from MASM with JMP

北慕城南 提交于 2019-12-11 19:24:30
问题 I would like to execute the following commands in MASM: jmp far PTR 0:61Dh jmp far ptr 2000h:0 jb short near ptr 106h The first two are producing error A2206: missing operator in expression and the third, error A2028: expression must be a code address. If anyone could advise as to how to make these functions work in MASM I would appreciate it. Thanks 来源: https://stackoverflow.com/questions/17931114/executing-segment-codes-from-masm-with-jmp

What is the difference between “PTR” and “NEAR PTR”?

≯℡__Kan透↙ 提交于 2019-12-11 18:29:03
问题 I was looking up examples containing “NEAR PTR”, but they were easily replaceable with “PTR”. Is there any advantage for using “NEAR PTR”? 回答1: NEAR is a legacy from 16-bit past. Assuming your code is 32-bit or 64-bit, they are the same. This is about memory segments (Wikipedia link to x86 32-bit and to 64-bit). In LABEL statement both PTR and NEAR PTR just store a 32/64 bit memory address without segment. If compile next code under 64-bit MASM: _DATA SEGMENT justPtr LABEL PTR db nearPtr

Converting lowercase character string to uppercase masm

耗尽温柔 提交于 2019-12-11 17:57:44
问题 there is a printf statement which tells the compiler to print outStr. outStr is originally set to equal emptybuf[1000] = "??? not translated yet ???";. I am supposed to move my answer into the outStr, which should update the outStr in the print statement. For some reason my inline assembly will not print out anything from the code shown below. I cannot understand what I am doing wrong. I am trying to convert lowercase letters to uppercase, and ignore any special characters. Any advice is much

Counting letters and printing an array of numbers with windows api

橙三吉。 提交于 2019-12-11 17:23:22
问题 I have an user input string, which was lowercased and all special characters removed target2 and I want to count how many times each letter appears on the string, and then print the array with 26 letters. However, it prints just a blank line. Is the error when I add to the array? when I print from the array, or both? If I watch letterArray , it says 1 '\x1' What does that mean? lettersArray byte 26 dup(0) countingLetters proc ; clear esi and edi mov esi, 0 mov edi, 0 charloop mov al, target2

How to calculate the sum of a sequence of powers of 2 in x86?

感情迁移 提交于 2019-12-11 14:54:31
问题 I want to calculate a sequence of exponents of base 2. for example if given 3 the program would calculate (2^3 + 2^2 + 2^1 + 2^0). The problem is I cant calculate the exponent to being with. I have tried shl to calculate the exponent and I have tried a loop. Neither produce the correct result, my latest attempt is below. .586 .MODEL FLAT INCLUDE io.h .STACK 4096 .DATA Exponent DWORD ? Prompt BYTE "Enter an exponent", 0 Base DWORD 2 string BYTE 40 DUP (?) resultLbl BYTE "The solution is", 0