Issues with general purpose registers | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок

Issues with general purpose registers

Hey everyone! I've wrote a simple Assembly script to print a list of numbers from 0-6 in the console. But once I'm still learning to use the language, for a better practice, I focused on using nothing but registers to hold data, using the eax register as the list range, and the ebx register as an indexer. Such usage seemed to be ok to me. But after assembling and linking the code, I tried to run the .exe file and got a totally different output. Here's the source-code: main PROC LOCAL n:DWORD mov eax, 6 ; Works if eax is replaced for the "n" variable mov ebx, 0 COMPARE: cmp ebx, eax ; Works if eax is replaced for the "n" variable jl FNC jg BREAK FNC: print str$(ebx) print chr$(13, 10) jmp INCECX INCECX: inc ebx jmp COMPARE BREAK: ret main ENDP The logically expected output was: 0 1 2 3 4 5 6 But instead the code is generating multiple different outputs: - Using eax as indexer: - Output: 0 1 2 - Using ecx as indexer - Output: 0 - Using edx as indexer - Output: 0 1 2 3 4 5 6 7 8 ... and so on As much as my knowledge allows me to assume, these registers are for general purpose, so I find a lot strage that these aren't holding values correctlly. I'm using MASM v6.14.8444 and MASM Incremental Linker v5.12.8078 I'd be thankful if you could help me on this. Thanks.

4th Jan 2019, 11:58 PM
Silas Junior
Silas Junior - avatar
1 ответ
+ 2
print isn't a hardware instruction. It generates code using registers to make a system call clobbering your values. I've not played with masm so can't tell you what it uses and my attempt to search it came up empty.
5th Jan 2019, 2:17 AM
John Wells
John Wells - avatar