Problems for displaying results of programs

Started by flicka, July 29, 2005, 04:05:35 AM

Previous topic - Next topic

flicka

I've done a couple programs but I encounter always the same problem: I don't seem to know how to get the program to display what I want to. In this program I'm creating a table of elements but I can't get to see the results. Could anyone help me figure out how to display something.
Here is the program I made: 
              .MODEL SMALL
              .STACK 64
              .DATA
LEN_STKNO EQU  02                         ;Length stock no.
LEN_DESCR EQU  09                         ; and description
STOCKN_IN DB   '12'                       ;Input stock no.
STOCK_TBL DB   '04','DVDs     ','22.20'   ;Start of table
          DB   '07','Receivers','95.75'   ;
          DB   '14','Modems   ','47.45'   ;
          DB   '17','Keyboards','49.35'   ;
          DB   '24','Diskettes','12.95'   ;End of table
.386  ; -------------------------------------------
              .CODE                ; Define code segment
A10MAIN   PROC NEAR
          MOV  CX,06              ; Initialize
          LEA  SI,STOCK_TBL       ; compares
A20:      MOV  AL, STOCKN_IN
          CMP  AL, [SI]           ; Stock#(l) : table
          JNE  A30                ; Not equal, exit
          MOV  AL,STOCKN_IN+1     ; Equal:
          CMP  AL, [SI+1]         ; stock#(2) :table+1
          JE   A50                ; equal, found
A30:      JB   A50                ; Low, not in table
          ADD  SI,LEN_STKNO       ; High, get
          ADD  SI,LEN_DESCR       ; next entry
          LOOP A20
A50:
          INC  SI
          INC  SI                 ; Extract description
          MOV  AX,13H             ; Request display
          MOV  BP,SI              ; Stock description
          MOV  BX,0061H           ; Page:attribute
          MOV  CX,LEN_DESCR       ; 09 characters
          MOV  DX,0812H           ; Row:column
          INT  10H
          RET
A60:      ENDP                    ; End of procedure
          END  A10MAIN            ; End of program


Thanks.

vitsoft

BIOS Video functions expect the function number in AH but you are loading it into AL.
Change the line
MOV  AX,13H             ; Request display
to
MOV  AX,1301H             ; Write string, update cursor

flicka


raymond

A few more discrepencies.

a) You initialize your counter CX to 6 but you only have 5 items in your table!!!

b) After you check the first item in your table, you adjust the pointer SI for the length of the stock number and the length of the description. According to your .DATA section, that pointer would then be the address of the start of the "22.20" and not the start of the stock number of the next item!!!

N.B. Because your stock number has only 2 digits, you can compare those two digits in a single operation as follows:

A20:      MOV  AL, STOCKN_IN
          MOV  AH,STOCKN_IN+1
          CMP  AX, [SI]
          JE   A50                ; equal, found


Raymond
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

MichaelW

Flicka,

In addition to the problems already pointed out:

The display code is destroying the loop counter.

The display code is entered with a jump so the return instruction is using an invalid return address.

There is no code to properly terminate the program.

And most importantly, the code contains a syntax error that prevents it from assembling, which suggests to me that you just threw it together and posted it without testing, hoping someone would fix it for you.

http://www.masmforum.com/simple/index.php?topic=1295.0


eschew obfuscation

flicka

#5
Michael
I'm sorry but I didn't just through it together and hope to have someone fix it for me...
I have spend every evening this week on it.  I wake up a 7AM get ready to work from 8AM to 4PM , then take care of my baby after I pick him up from daycare and once he is in bed around 7PM until 3AM I work on trying to understand and learn Assembly language. Some night I don't even get to sleep, because a accident occured and we are called out to help save a life and prevent further accidents. Try a few time doing 48H strait staying awake!  I have tested it and don't get anything but errors and check in my book and can't find anything to help me. The book I have only has "partial programs" to explain a specific ideea but doesn't have one "real" program from A to Z to show as example.

So I'm doing the best I can to understand this language that I think will be helpfull in the future. And I came here hoping someone would point me the problems, help me understand what is wrong so that I learn something That loop and the display were two parts in the book I have and I AM TRYing to understand and do things right....

If this is not a place where I can find people help me to learn Assembly then It's sad.

Mark Jones

Well not everyone has years of assembly experience such as Michael, he makes anything look easy. Truth is, it is hard for a newcomer to learn. Just keep at it and remain patient.

Also get some sleep instead of coding all night, then suddenly everything will make much more sense. :bg
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

flicka

Thanks Mark!
:wink I hopefully will get some sleep, if another major accident doesn't happen this night.
Unfortunately night time is the only "free time" I have to learn. I'm going to hang in there!
.