News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

basic counting

Started by nofx, September 20, 2006, 12:07:41 PM

Previous topic - Next topic

nofx

Hello, i want to make a simple app that loads the value '1000' into the memory, and then i want to decrease that value until its 998.
The thing is that i dont want to use a loop, but i need to use something like shl.
Here is an example of how i thought it's gonna be (sort of).



.MODEL SMALL
.CODE

mov eax, 1000
shl eax, 999
shl eax, 998

END
[/cpde]

So im trying to point to load the a new value in the next memory location, but im not sure if shl points to the next memory location...
I also would like to know how i could print the value of eax to the DOS screen so i can see where i go wrong.

mnemonic

There are some issues with your thoughts and code.

First thing is, how are you going to count by a certain increment/decrement without using a loop or unroling (which is basically a looping process by invariable/static steps)?

Then you seem to have a basic misunderstanding in what "shl" does.
Here a quote from opcodes.hlp:
SHL - Shift Logical Left

        Usage:  SAL     dest,count
                SHL     dest,count
        Modifies flags: CF OF PF SF ZF (AF undefined)
        .-.     .---------------.     .-.
        |C|<----|7 <---------- 0|<----|0|
        '-'     '---------------'     '-'
        Shifts the destination left by "count" bits with zeroes shifted
        in on right.  The Carry Flag contains the last bit shifted out.

Read that and realize, that it just makes no sense shifting a 16/32bit value 999 times to the left.

How to convert binary numbers to decimal strings should be explained more than once in the 16bit forum and I think that your question fits better there.  :wink
Some Moderator will certainly move the topic there.
Be kind. Everyone you meet is fighting a hard battle.--Plato
-------
How To Ask Questions The Smart Way

nofx

Yeah i already thought that shl wasn't what i needed, thanks for clearing it up.
I have another thing now though, i've got this code:


.model small
.stack
.data

.code

main proc

mov eax, 1000
dec eax
dec eax
dec eax

main endp
end main


If i try to assemble this, then i get this error message


Quote
test.asm(4) : error A2085: instruction or register not accepted in current CPU
mode

Im on Windows XP incase you're wondering. Any idea what could've gone wrong??

mnemonic

Add
.386
before the
.model small
line and you should be fine. If not otherwise stated, MASM assumes that you write code for the 8086 machine and that one only had 16bit registers.  :wink
Be kind. Everyone you meet is fighting a hard battle.--Plato
-------
How To Ask Questions The Smart Way

nofx

Thanks, it did compile without any errors :)
But there's one thing that i would like to know, how can i print the value of eax to the DOS screen...???

mnemonic

As I said: You will find the answer here.
I found it in less than a minute: http://www.masm32.com/board/index.php?topic=163.0

:wink
Be kind. Everyone you meet is fighting a hard battle.--Plato
-------
How To Ask Questions The Smart Way

nofx

heh, thats to hard for me to understand...
But i know now how to work with the assembler program, so i'll just start with reading a few tutorials here and there to expand my knowledge.
Thanks for your help, you'll probably see more question come by sooner or later :)

mnemonic

Quote from: nofx on September 20, 2006, 08:48:12 PM
heh, thats to hard for me to understand...

Heh, you're dealing with assembler, so you should not consider anything as "too hard to understand".  :wink
If there is something you do not understand you should ask in the corresponding thread. Noone will tear you apart.

There is nothing more than just some basic math involved. Read the algorithm in some days again and you will smile.

And maybe you are intersted in a small exercise: Calculate the "sum of digits" of a given 32bit value.
E.g.: the "sum of digits" (SOD) of 123 is: 1+2+3 = 6
SOD of 638 = 6+3+8 = 17
and so on...

We all grow by our challenges.  :U

Have fun.
Be kind. Everyone you meet is fighting a hard battle.--Plato
-------
How To Ask Questions The Smart Way

nofx

Thats a nice exercise, but even that is still too hard for me  :red
But dont give any hint yet, im gonna read through some stuff first and then i'll come back on this subject.
So just give me a few days  :U