Math Help Forum

Math Help Forum Feed Site Feed

Go Back   Math Help Forum > MHF Lounge > Chat Room
Reply
 
Thread Tools Display Modes
  #1  
Old June 7th, 2009, 07:16 AM
Member
 
Join Date: Feb 2009
Posts: 125
Country:
Thanks: 59
Thanked 0 Times in 0 Posts
gammaman is on a distinguished road
Default Anyone know assembler?

Is there anyone here who knows MASM assembly language? If so, would anyone be willing to take a look at a simple program that I started to comment? See I want to make sure that I am understand what is going on in the program. The best way to do that is by commenting the program. If anyone is willing to see if I am on the write track, please reply and I will post the code.
Reply With Quote
Advertisement
 
  #2  
Old June 7th, 2009, 11:07 AM
Super Member
 
Join Date: Jan 2009
Posts: 592
Country:
Thanks: 69
Thanked 133 Times in 123 Posts
aidan will become famous soon enoughaidan will become famous soon enough
Default

Quote:
Originally Posted by gammaman View Post
Is there anyone here who knows MASM assembly language? If so, would anyone be willing to take a look at a simple program that I started to comment? See I want to make sure that I am understand what is going on in the program. The best way to do that is by commenting the program. If anyone is willing to see if I am on the write track, please reply and I will post the code.

I'd like to take a look.

I've written several programs (a CriticalPath/Pert program; a chess program; and dozens of other little buggers) using MicroSoft Assembler, and a bunch of one shot snippets.

If the code is short (about 5 printed pages) I do not see a problem listing it here. However, if it is longer than that it would be best to post it elsewhere and provide a link to it.

My opinion.
Check with the mods for non-math posts.
Reply With Quote
  #3  
Old June 7th, 2009, 11:53 AM
Member
 
Join Date: Feb 2009
Posts: 125
Country:
Thanks: 59
Thanked 0 Times in 0 Posts
gammaman is on a distinguished road
Default

Yes it is very short. Again I just really want some help commenting the code and some input on what I have already commented.

Code:
title prog3
;this program eliminates a number from a list specifically, 50
.model small
.stack 100h                         ;256 byte stack    
.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
Reply With Quote
  #4  
Old June 9th, 2009, 06:05 AM
Super Member
 
Join Date: Jan 2009
Posts: 592
Country:
Thanks: 69
Thanked 133 Times in 123 Posts
aidan will become famous soon enoughaidan will become famous soon enough
Default

Quote:
Originally Posted by gammaman View Post
Yes it is very short. Again I just really want some help commenting the code and some input on what I have already commented.

Code:
title prog3
;this program eliminates a number from a list specifically, 50
.model small
.stack 100h                         ;256 byte stack    
.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
 
;move up the remaining items
      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
The items highlighted in blue are meaningful. They tell me something that at first glance explains what's up.

"in base 10 format" is beautiful.
normally it is hex, but this clarifies intent!

The highlighted red information, merely states exactly what the instruction is doing. There is nothing "wrong" with that, but it does not help.
In a few months when you look at something like
Code:
 
delete proc
 add bx, ax  ;next value in data array
 sub cx, ax  ;items remaining
will give you an immediate idea of what is being done.
With your existing comment you will have to spend a few seconds to study the group of instructions before you come to the same conclusion.
You want to MINIMIZE your time when looking at code.

The lines highlighted in fuscia or pink [or whatever that color is] just makes a statement of what is occuring. When you review this (if ever you need to re-use code) the snippet becomes more like a paragraph and you can become more effective.

For me, one of the most helpful things, at the start of a procedure:
list the registers and identify what each contains;
state what is INTENDED to be done
and
which registers have valid data at exit.

Remember, there is no right or wrong way to comment your code.
[unless, of course, you are a member of a group that must alter/change each others pieces of code, that all are part of a larger product, then, naturally there is a RIGHT way of doing it.
As the boss says, "my way or you are deleted"]

The real value of the comments is that they will save you a lot of grief a few weeks/months/years down the way.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -7. The time now is 06:29 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.
©2005 - 2009 Math Help Forum


Math Help Forum is a community of maths forums with an emphasis on maths help in all levels of mathematics.
Register to post your math questions or just hang out and try some of our math games or visit the arcade.