News:

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

loop from positive to negative values

Started by thomas_remkus, March 06, 2008, 03:18:04 AM

Previous topic - Next topic

thomas_remkus

I'm getting a little lost here. I'm trying to create a small loop that will put 10 in ECX and 5 in EDX and I am trying to DEC my EDX 10 times so I can output the following values:

5
4
3
2
1
0
-1
-2
-3
-4


I'm having issues. I don't seem to be able to take my number from 0 to -1 properly. Is there an DECS ?? This sounds really easy but I can't seem to get round it.

BogdanOntanu

The first issue you have if that you do not know to explain your problem into great details.

Tell me this: do you expect us to read your mind, find the source code you have written and then fix it  and put it back into your mind?

If not then please show us the code sequence you have written and then we might be able to give you hints about what you are doing wrong... otherwise we have to guess...

And NO there is no "DECS" instruction, only DEC
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

Tedd

I see Bogdan's in a good mood again ::)


The problem is that signed values are really just a hack - there's no difference between a byte with the value 255 and one with the value of -1 -- they are both still FFh.  The only difference is in how you decide to treat them.
So, when you subtract 1 from (dword) 0, you will get 4294967295 (FFFFFFFFh). And that is correct. The difference between using signed and unsigned is what you decide it means. If all you're doing is printing, then you need to use a print function that will treat any values you give it as signed, and thus print "-1" rather than "4294967295"
No snowflake in an avalanche feels responsible.

thomas_remkus

This campus section is supposed to be ,"A protected forum where programmers learning assembler can ask questions in a sensible and safe atmosphere without being harassed or insulted." Mr. BogdanOntanu, I don't think you have properly followed this criteria. And I think if I could have explained my problem in greater detail I don't think I would have asked the question in the first place. If you could read my mind, find the source, fix it, and put it back into my mind that would be something. I will humble myself a little more and try and post code for each question I have relating to code.

Tedd, thank you for your response. That's perfect knowledge and a gap I'm happy to fill.


hutch--

thomas,

forget re-interpreting the rules, Bogdan is correct that you have provided no source code to test or fix. The idea is to provide your efforts and members here will help you. Just write up your source code and show us what you are trying to do and someone can probably help you but we are not mind readers.  :bg

Here is a quick example.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    .code

start:
   
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    call main
    inkey
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc

    push esi

    mov esi, 10

  lbl0:
    print sstr$(esi),13,10          ; NOTE signed string conversion
    sub esi, 1
    cmp esi, -10
    jge lbl0                        ; NOTE signed Jcc

    pop esi

    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start

OUTPUT to SCREEN.

10
9
8
7
6
5
4
3
2
1
0
-1
-2
-3
-4
-5
-6
-7
-8
-9
-10
Press any key to continue ...
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

herge


Hi Thomas:

Also remember negative numbers are usually Huge integer values
So make sure you have signed output.
// Herge born  Brussels, Belgium May 22, 1907
// Died March 3, 1983
// Cartoonist of Tintin and Snowy

thomas_remkus

I will, when appropriate provide code examples relating to all my questions. Thanks Hutch for making sure I stick to this.