News:

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

help commenting code

Started by gammaman, June 05, 2009, 04:12:31 PM

Previous topic - Next topic

dedndave

learning assembler is not hard, really
there is a lot of material, with regard to learning the API functions
you do not need to know all the API functions to write code
the thing is, most of us are here because we enjoy it
don't look at it like a task - make a hobby out of it - attitude is everything
in the end, you will find it fun and rewarding

UtillMasm


gammaman

Hello it is me again.  Here is another program I need to comment.  I started to work at it, I am not asking for help, I just want to know if I am on the right track.  By the way I spoke with my prof and the way he wants us to comment the program is to tell him what each instruction is doing.


.data
        array db 10, 20, 30, 40, 50, 60, 70, 80, 90
        arraysize dw 9
.code
      main proc
        extrn writeint:proc, crlf:proc               ;Writeint.obj found in fierro.lib,Crlf.obj found in fierro.lib
        mov ax, @data      ;copy the address of the data segment
        mov ds, ax            ;@data into ds register
        mov bx, offset array      ;get the address of array into bx
        mov cx, arraysize      ;put arraysize into cx register
        mov ax, 4
        call delete
        call printout
        mov ax, 4c00h
        int 21h
        main endp

        delete proc
        add bx, ax      ;add value in ax to value in bx
        sub cx, ax      ;subtract ax from value in cx
        dec cx
        repeat:

        mov ax, [bx+1]
        mov [bx], ax
        inc bx
                   
        loop repeat
        ret
        delete endp

        printout proc
        mov si,0
        mov cx, arraysize
        dec cx     ;decrement the cx register
               
        again:
        mov ah,0
        mov al, [array + si]
        mov bx, 10
        call writeint     ; in base 10 format

        mov dl, " "
        mov ah, 2     ;dispay character function
        int 21h

        inc si                                      ;use si to count how many times we push onto the stack
        loop again
        ret
        printout endp
        end main

dedndave

well - comments like "add value in ax to value in bx" don't tell the reader anything
the comments should tell the reader what is going on in the program
in other words, they should explain the purpose of the instructions, rather than the method of achieving it

let's call the "4" value an index

        mov bx, offset array  ;array pointer in bx
        mov cx, arraysize     ;array length (count) in cx
.
.
.
        add bx, ax            ;add index to pointer
        sub cx, ax            ;subtract index from count



mitchi

What kind of homework is that. Commenting stuff... The teacher must be a noob with assembly.

UtillMasm

 :lol
oh my fo!
you are talking about teacher.

dedndave

yes - if you read previous posts....
the prof said, "I am not going to teach you assembler because that would take 2 semesters"
or something to that effect

this is the second program we have seen from this prof
he should have said, "You will know more about assembler than I do at the end of the summer"

on another thread, the prof wants them to design a serial com circuit
i wonder if he needs it for a contract job ? - lol
(i have seen that happen quite a few times - the results can range anywhere from exceptional to crappy)

i usually don't like working with profs on a job
with one exception - Dr Dave Pheanis - a true wizard and a tough instructor (i know - lol @ the name)
at Sperry Flight Systems, he was in our group - a few of the other engineers had had him as an instructor
they were all afraid of him - lol
but, he is a nice guy as long as he isn't your prof
too bad he doesn't hang in here (probably no time)

http://www.fulton.asu.edu/fulton/people/page.php?profile=149

Mark Jones

Quote from: Mark Jones on June 06, 2009, 05:57:59 PM
...
Download the MASM32 package and see \masm32\help\opcodes.chm for each of those instructions.
...
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

gammaman

I just tried to run the program, and I guess my prof screwed up when he gave it to us because it contains two errors.

Line 27:  repeate:   error: missing operand after unary operator
Line 55:  end main:  error:unmatched macro nesting


dedndave

repeat is a reserved word

delete might also be a reserved word - not sure - don't use words like that

in the delete proc - he has dec cx - take that out <--- not sure about that one
i lose the guy right there - not sure what he is trying to do

this code....

        mov ax, [bx+1]
        mov [bx], ax

needs to be this....

        mov al, [bx+1]
        mov [bx], al

yah - i don't know what the program is supposed to do - it is not well written - lol
fix the reserved words
make sure you copied the code correctly


dedndave

i thought i knew what he was trying to do, but the code doesn't even come close to working - lol

gammaman

I asked my prof.  He said the program is supposed to remove the number 50 from the array.  I asked him about the errors and he said, "I don't know how to fix".

gammaman

did I mention that my prof is 65+, of Chinese decent, been in America for over 50 years, cannot speak a lick of English.  The man does not teach, he talks to the blackboard and rarely addresses the class.  Try sitting through that for 3 hours straight.  I'd rather get a root canal.

dedndave

lol
that rings a bell
one of my physics intructors was from Formosa
his name was - wait for it....... Dr Who
lol
he was actually a very sharp guy - kind of young
his specialty was optics, which is ok, but, at the time, wasn't one of my favorite parts of physics
i have become more interested in it over time
anyways, when we came to the part about reflection and refraction, it became very difficult to understand him
when a Chinese person says, "reflection", they quite often wind up saying "refrection"
hard to know whether we were talking "refrection" or "refraction" - lol
anyways, i liked Dr Who - he was a good guy - and i got an A - lol - that helps, too
i always liked physics anyways

dedndave

ok - so put the dec cx back in
the ax,[bx+1] should be al,[bx+1]
the ax,[bx] should be al,[bx]

if you change the word "repeat" to some other name, that will get rid of one error
as for the main nesting error - it may be related to the repeat error, as that could have caused a phase error
but - i always put the names of procedures all the way to the left of the page when opening and closing procs

main    proc
        ret
main    endp

like that - that might help