Results 1 to 2 of 2

Thread: Example Program rewrite.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    348

    Example Program rewrite.

    I have found a couple tutorials online to learn assembly, and I need help compiling one of them. The example compiles but my rewrite will not.
    Code:
    ;EXAMPLE 
    .386
    .model flat, stdcall
    option casemap :none
    include \masm32\include\windows.inc
    include \masm32\include\kernel32.inc
    include \masm32\include\masm32.inc
    includelib \masm32\lib\kernel32.lib
    includelib \masm32\lib\masm32.lib
    .data
    ProgramText db "Hello World!", 0
    BadText db "Error: Sum is incorrect value", 0
    GoodText db "Excellent! Sum is 6", 0
    Sum sdword 0
    .code
    start:
    ; eax
    mov ecx, 6 ; set the counter to 6 ?
    xor eax, eax ; set eax to 0 0
    _label: add eax, ecx ; add the numbers ?
    dec ecx ; from 0 to 6 ?
    jnz _label ; 21
    mov edx, 7 ; 21
    mul edx ; multiply by 7 147
    push eax ; pushes eax into the stack
    pop Sum ; pops eax and places it in Sum
    cmp Sum, 147 ; compares Sum to 147
    jz _good ; if they are equal, go to _good
    _bad: invoke StdOut, addr BadText
    jmp _quit
    _good: invoke StdOut, addr GoodText
    _quit: invoke ExitProcess, 0
    end start
    Now here is my rewrite.
    Code:
    .386
    .model flat, stdcall
    option casemap :none
    
    include \masm32\include\windows.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc
    include \masm32\include\masm32.inc
    
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib
    includelib \masm32\lib\masm32.lib
    
    .data
        SumError db      "Error: Sum is incorrect", 0
        Sucess   db      "The Sum is Correct", 0
        Sum      sdword  0
    .code
    
    start:
        mov     ecx, 6
        xor     eax, eax
    _label: 
        add     eax, ecx
        dec     ecx
        jnz     _label
        mov     edx, 7
        mul     edx
        push    eax
        pop     Sum
        cmp     Sum, 147
        jz      _good
    _bad:  
        invoke  StdOut, addr SumError
    _good: 
        invoke  StdOut, addr Success
    _exit: 
        invoke  ExitProcess, 0
    
    end start
    Please Help Us To Save Ana

    -If you have been Helped, Please Mark Thread [Resolved] using Thread Tools

    -If someone has helped you, Please rate their post.

  2. #2
    Member
    Join Date
    Oct 2006
    Posts
    53

    Re: Example Program rewrite.

    .data
    SumError db "Error: Sum is incorrect", 0
    Sucess db "The Sum is Correct", 0

    _good:
    invoke StdOut, addr Success

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width