MASM

Modifying a character array, the modified part shows up backwards

 ̄綄美尐妖づ 提交于 2019-12-11 05:46:15
问题 I have just started learning assembly, and I am trying to modify a character array. This is my assembly code: .data data byte 'Five', 0 .code Asm proc lea rax, data mov dword ptr[rax], 'Four' ret Asm endp end And my C++ code: #include <stdio.h> #include <conio.h> // external function extern "C" char* Asm(); // main function int main() { printf(Asm()); _getch(); } When I comment out mov dword ptr[rax], 'Four' , the result is that the console prints: "Five" . But, with the above code

x86 assembly - masm32: Issues with pushing variable to stack

女生的网名这么多〃 提交于 2019-12-11 05:25:43
问题 I'm trying to make a program that gets two input numbers, multiplies them (storing the result in a variable), divides them (storing the result in another variable) and prints the result. The issue I'm having is that the first line of code push num1 returns invalid instruction operands : .data num1 db "Enter a number:" num2 db "Enter another number:" .data? buffer1 dd 100 dup(?) ; this is where I store input for num1 buffer2 dd 100 dup(?) ; " " num2 .code start: push num1 ; here is where it

selection sort in assembly language

十年热恋 提交于 2019-12-11 04:58:32
问题 here is my code.. I have to perform a selection sort on an array. It is homework. The Irvine32.inc sets up my memory model. Any suggestions to what I'm doing wrong would be helpful. I've redone the entire thing a few times now. INCLUDE Irvine32.inc .data myArray DWORD 10, 12, 3, 5 .code main PROC call Clrscr MOV EDI, OFFSET myArray MOV ECX, LENGTHOF myArray CALL PRINT_ARRAY MOV EDI, OFFSET myArray MOV ECX, LENGTHOF myArray CALL SORT_ARRAY CALL CRLF MOV EDI, OFFSET myArray MOV ECX, LENGTHOF

\ch03\AddSub.asm(45): fatal error A1010: unmatched block nesting : IsPrime

依然范特西╮ 提交于 2019-12-11 04:41:04
问题 INCLUDE Irvine32.inc .code main PROC .REPEAT mov edx, OFFSET fPrompt ;display a prompt call WriteString call ReadInt ;recordes users number mov var1, eax ;gives var1 the users number .IF var1 == -1 ;jumps to L3 if the user want's to quit jmp L3 .ENDIF call IsPrime ;calls the IsPrime procedure L3: .UNTIL var1 == -1 ;jumps up to repeat if var1 != -1 ret main ENDP mov ebx, 2 ; sets minimum divisor mov eax, var1 ; set dividend cdq ; converts to 64-bit edx:eax mov ecx, ebx ; stores divisor in ecx

MASM: .IF with signed numbers comparison

时光毁灭记忆、已成空白 提交于 2019-12-11 03:22:30
问题 I have: mov ecx, r .if ecx < 0 mov cl, 0 .elseif ecx > 255 mov cl, 255 .endif mov [eax + 2], cl r is signed integer. I want it to cap it within byte limit. But problem is when "r" is negative. It is treated as if it is unsigned. Input -> Expected output r = 300 -> 255 r = 12 -> 12 r = -134 -> 0 What actually happenes: r = 300 -> 255 r = 12 -> 12 r = -134 -> 255 <--------- Here it gets treated as if -134 is bigger than 255 How to fix it? 回答1: Shortest solution: .if SDWORD PTR ecx < 0 来源: https

Converting Uppercase to Lowercase in Assembly issue

一曲冷凌霜 提交于 2019-12-11 01:34:14
问题 I'm writing to convert a pre-set string from Uppercase to Lowercase. I'm currently moving what is at the address to an 8bit register, then doing a very sloppy way of testing the ASCII value to see if it's Uppercase. Is there a cleaner way to go about it? Right now I'm subtracting 65 from the ASCII value and comparing to 25. Since uppercase is ASCII (dec) 65-90, any uppercase letters will result in 0-25. .DATA string DB "ATest This String?.,/[}", '$' strSize DD 23 .CODE strToLower PROC LEA EAX

Macro printing a value stored in a byte. Assembly masm

吃可爱长大的小学妹 提交于 2019-12-10 21:57:32
问题 Assembly, masm Hey, I wrote macro which prints the 1 byte value stored in dane1 segment. I divide the value by 16, then i push reminder to stack until value==0. Then I pop reminders convert them to ASCII code, and print them. Shall someone look at my code? What should I change to make it simpler? I don't want to do each time: mov dl,67h mov ds:[v1],dl print v1 Is it possible to modify this macro, so that it could use it: print 67h print al Thanks for any help. assume cs:code1 .186 dane1

Add 2 numbers in assembly language and print the result

情到浓时终转凉″ 提交于 2019-12-10 19:35:02
问题 need help, how to add two numbers and then print the result here is my code .MODEL SMALL .STACK 200H .DATA NUM1 DB 12 NUM2 DB 3 VAL DB ? MSG1 DB "The sum is : $" .CODE BEGIN PROC MOV AX, @DATA MOV DS, AX MOV AL, NUM1 ADD AL, NUM2 MOV VAL, AL LEA DX, MSG1 MOV AH, 9 INT 21H MOV AH, 2 MOV DL, VAL INT 21H MOV AX, 4C00H INT 21H BEGIN ENDP END BEGIN I got an output that says The sum is 0 What is the error to my code? 回答1: By dividing the value constantly by 10 you'll get the single digits in the

DOS Interrupt in masm x86 assembly crashing

≡放荡痞女 提交于 2019-12-10 18:36:33
问题 I've just begun learning some x86 assembly on win32, and I've used masm with visual studio 2008 using the custom build rule that comes with the ide for .asm files. I've been trying to use the DOS interrupt to print to the console, but instead I receive the message: "Unhandled exception at 0x00401004 in ASMTest.exe: 0xC0000005: Access violation reading location 0xffffffff." on the 8th line. I'm trying to output the single ascii character 'A' (41h) Here is the masm code: .386 .MODEL flat,

how does AAA work in 8086 instruction set?

谁都会走 提交于 2019-12-10 18:06:13
问题 There is some info regarding the algorithm how the instruction works: if low nibble of AL > 9 or AF = 1 then: AL = AL + 6 AH = AH + 1 AF = 1 CF = 1 else AF = 0 CF = 0 in both cases: clear the high nibble of AL. Example: MOV AX, 15 ; AH = 00, AL = 0Fh AAA ; AH = 01, AL = 05 RET But the problem i am facing is when I replace 15 in the above example with numbers like 00FF and 00FA the value in AH gets incremented by 02 instead of 01 !! Why are these changes ?? 回答1: Here is the detailed