hello,
this is my code and for some reason it does not work :/ could someone tell me whats going wrong?
;sum of all powers of 2 lower or equal to 2^n
;example n=4 => 2+4+8+16=30
.386
.model flat, stdcall
option casemap: none
include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\kernel32.lib
.data
good db "that is correct :)",0
bad db "that is not correct :(",0
sum sdword 0
.code
start:
mov ecx,4 ;counter
xor eax,eax ;eax will contain sum
_label:
mov bx,1 ;stores 1 in bx
;(mov cl,ecx)
shl bx,cl ;bx=1*2^cl
add eax,ebx ;add bx to eax
dec ecx ;lower counter
jnz _label ;loop until ecx=0
push eax ;eax=16+8+4+2=30
pop sum ;pop value of eax in sum
cmp sum,30 ;compare sum to 30
jz _good ;if sum=30 jump to _good
_bad:
invoke StdOut,addr bad
jmp _quit
_good:
invoke StdOut,addr good
_quit:
invoke ExitProcess,0
end start