Quote Originally Posted by Evgeni
I'm a VB and a C++ programmer and just started to learn asm. I'm trying to replicate my old c++ newbie programs into asm code. One of the programs i tried to replicate is an easy one it just draws a right triangle in console mode with asterisks.
Asm Code:
Code:
main proc

    LOCAL x:DWORD
    LOCAL y:DWORD
    LOCAL inptVal:DWORD

    mov eax, sval(input("Height of the triangle:"))
    mov y,0

    YLoop:
        print chr$(13,10)
        mov x,0
        add y,1
        mov ebx,y
        cmp y,eax
        jg Done
        XLoop:
            add x,1
            cmp x,ebx
            jg YLoop
            print "*"
            jmp XLoop

    Done:
    mov inptVal, input("Press any key to continue . . .") 
    ;to halt and let the output be seen

    ret

main endp
For some reason it just does 2 lines of asterisks.
You may want to start commenting you're code more hehe. ASM can be extremely hard to read if it's not commented. If this algorithm would have been a more complex one, I wouldn't have been able to help you.

The first thing I see is that you're using EBX without saving it. That's a big no no in windows. The only registers you can use without saving them are eax, ecx, and edx. If you want to use the other registers you must push them onto the stack first and pop them off once you're finished using them.

The reason you are seeing 2 lines of asterisks is because of the print statement you are using. That macros makes use of the eax register which is what you are using to store the height of you're triangle.

push ebx

mov eax, sval(input("Height of the triangle:"))
mov y,0

YLoop:
push eax
print chr$(13,10)
pop eax
mov x,0
add y,1
mov ebx,y
cmp y,eax
jg Done
XLoop:
add x,1
cmp x,ebx
jg YLoop
push eax
print "*"
pop eax
jmp XLoop

Done:
mov inptVal, input("Press any key to continue . . .")
;to halt and let the output be seen

pop ebx
You need to re-write this code and not use the ugly push and pop btw. You may also want to get rid of the variables and just use registers =)

xor eax, eax is a good way to set a register to 0.

peace!