The MASM Forum Archive 2004 to 2012

Miscellaneous Forums => 16 bit DOS Programming => Topic started by: Jalano on February 03, 2007, 08:38:01 PM

Title: Urgent Intel help
Post by: Jalano on February 03, 2007, 08:38:01 PM
I  am  beginner, trying to use masm6.11.  (Intel 8086)
How do I point to these values without using "inc" or  #[SI].
The displacement value comes frm a memory location that produces various values based on
previous cod conditions.  eg.  I might table to be loaded in SI  ("DATA_1" amount of times)

          ORG 100H
TABLE     DB    '0', '1', '5' ,'3' ,'4' ,'8' ,'6' ,'7' ,'8' ,'9'

if I do

"mov si, OFFSET TABLE "

Si would hold the value for 0, which is 30H.

Let's say I want to point to '8'.  What do I do without having to tyoe "8" in the code.


I really really need help as soon as possible.
Title: Re: Urgent Intel help
Post by: TNick on February 03, 2007, 08:55:47 PM
Hello! Welcome aboard!


mov   si,  TABLE
mov   si,  TABLE[0]
;both instructions put "0" in si
mov   si,   TABLE[2]
;put "5" in si


This is a quick answer, there are another ways. You should do some reading, 'cause this stuff is in the intro part of any material concerning assambly!
Forum search and your favorite search engine can do the job! :U

Regards,
Nick
Title: Re: Urgent Intel help
Post by: Jalano on February 03, 2007, 11:20:54 PM
Ok, but that is something that I did before.  However, I am upgrading a program that does division, and stores the remainder in a memory location "REM". 
si is alerady OFFSET to table. 
Let's say the contents of REM is suppose to take SI to a specific location in "TABLE" so that I could put it into a register for the 21H INT.
I.E.  I am suppose to get the correct displacement without typing in the displacement value.

              ORG   100H
REM          DB   ?
             
              ORG   140H
TABLE       DB   '0', '1', '2', '3', '4', 5', '6', '7', '8', '9'


My professor doesn't want me to do
 
                               mov al TABLE[3]

He wants the contents of "REM" to take it there. 
It has to be that way for later expansion, if "TABLE" contents change to Letters and HEX values.
I'm working hard at it, but no progress.

                         
note.  "REM" is remainder from a division function.
Title: Re: Urgent Intel help
Post by: eek on February 04, 2007, 12:32:49 AM
mov bp,TABLE
mov al,[bp+REM]
Title: Re: Urgent Intel help
Post by: sinsi on February 04, 2007, 01:22:01 AM
mov al,[si+(rem-table)]
Title: Re: Urgent Intel help
Post by: Jalano on February 04, 2007, 01:53:10 AM
Those do not work. 
Every other part of my code works but that part.  I have tried other ways pn my own, but It just ended up giving me the correct values, but not from mthe tabel.  I found that out when I re-arranged the numbers in the table to test it.
Title: Re: Urgent Intel help
Post by: sinsi on February 04, 2007, 02:10:53 AM
I really must learn to read the whole post... ::)
QuoteLet's say the contents of REM is suppose to take SI to a specific location in "TABLE" so that I could put it into a register for the 21H INT.
Try this
  movzx bx,rem
  mov al,[bx+si]

Title: Re: Urgent Intel help
Post by: Jalano on February 04, 2007, 02:31:39 AM
It says.
Instruction or register not accepted in current cpu mode.

Is movzx correct?
Title: Re: Urgent Intel help
Post by: eek on February 04, 2007, 02:35:57 AM
 :lol

mov bp,TABLE
add bp,REM
mov si,bp
mov al,[si]
Title: Re: Urgent Intel help
Post by: Jalano on February 04, 2007, 02:54:07 AM
The correct value shows up in si  and bp, but nothing goes into al.   At the same time, the value that goes into  si may look correct because the table goes in ascending order,  but when I changed the values in the table,  It was not actually pointing at the values "in" the table (it just added values to the 30H).  I already got this far since a week ago.   But, I am learning through u guys.
Title: Re: Urgent Intel help
Post by: sinsi on February 04, 2007, 03:07:23 AM
  mov bl,rem
  sub bh,bh
  mov al,[bx+si]


movzx is a 386(?) instruction...
Title: Re: Urgent Intel help
Post by: Jalano on February 04, 2007, 03:48:01 AM
It didnt work. 
Title: Re: Urgent Intel help
Post by: sinsi on February 04, 2007, 04:50:00 AM
If SI points to TABLE and REM has a valid (0,1,2...9) value then it should work. Post all of your code. Or fail your assignment  ::).
Title: Re: Urgent Intel help
Post by: Jalano on February 04, 2007, 05:14:52 AM
This is suppose to be part of 300 line code.   all other parts work.  I see nothing going into al.
     .MODEL SMALL
        .STACK 64
        .DATA

         ORG    100H
TABLE   DW      '0','1','2','3','4','5','6','7','8','9'

        ORG    140H
REM      DB    05H
        .CODE
          .STARTUP

PNT    PROC
  mov si, TABLE
  mov bl,REM
  sub bh,bh
  mov al,[bx+si]
   ret
PNT    ENDP
           END
Title: Re: Urgent Intel help
Post by: sinsi on February 04, 2007, 05:47:36 AM
Since you've declared TABLE to be words, you need BX*2

  mov bl,rem
  sub bh,bh
  shl bx,1
  mov al,[bx+si]

and use

  mov si,OFFSET TABLE

since you want the address of TABLE, not its first element
Title: Re: Urgent Intel help
Post by: eek on February 04, 2007, 10:10:54 AM
 :lol
Declare table as bytes IMHO, as it was originally

QuoteThe correct value shows up in si  and bp, but nothing goes into al.   At the same time, the value that goes into  si may look correct because the table goes in ascending order,  but when I changed the values in the table,  It was not actually pointing at the values "in" the table

Since we can't see all your code try some code segment overrides at the tricky bit, not sure of the syntax you guys use.

cs:mov al,[bx+si]   kinda thing


you could also try:

mov bp,TABLE
mov dl,[REM]
xor dh,dh
add bp,dx
mov si,bp
mov al,[si]

My previous feeble attempt added the word at REM to bp instead of the byte.
Title: Re: Urgent Intel help
Post by: Jalano on February 04, 2007, 04:49:16 PM
Thanks alot.  It works.  I'm now just trying to fix a loop problem.  After putting in key entries for the division, and it points and displays, after about 5 loops,  it starts displaying weird displacement values.  I think I should be able to fix that myself.  Thanks.
Title: Re: Urgent Intel help
Post by: Jalano on February 04, 2007, 04:51:29 PM
The last two solutions are good.
Title: Re: Urgent Intel help
Post by: Jalano on February 04, 2007, 05:00:22 PM
Actually, the last one still gives some problems, so I will stick with Sinsi's solution.  Thanks.