×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Arrays - Assembly x86

Arrays - Assembly x86

Arrays - Assembly x86

(OP)
Can anyone suggest a book or a good website so that I can understand how arrays work, and how to create them. I am a visual learner, and I need a book or website that uses visuals to demonstrate the process.

Thanks for any help you can give me.

 

RE: Arrays - Assembly x86

I'm not sure you'll get to see much help in too many venues.  Anyway, there's not going to be too much "visual" to get in anything (whatever you mean by that anyway?) anyway.  Or much clear and good - mostly just examples more than anything that is clearly explained.

Anyhow, here's something simple, hopefully you can understand it.  I'm trying to learn from some things I have here as well and can't say I'm acing anything for right now.

CODE

program count;
  { takes table, puts number in table that is index * 2,
    then prints it }
  var
    mytable: array[0..9] of byte;
    i: integer;

  procedure work; assembler;
    label
      loop_start1;
    asm
      MOV BX, Offset MyTable  { BX := offset of MyTable }
      MOV CX, 0               { CX := 0 }
      Loop_Start1:
      MOV AX, CX              { AX := CX }
      ADD AX, CX              { AX := AX + CX }
      MOV [BX], AX            { MyTable[i] := AX }
      INC CX                  { CX := CX + 1 }
      INC BX                  { BX := BX + 1 }
      CMP CX, 10              { is CX = 10? }
      JLE Loop_Start1         { jump to loop if CX <= 10 }
    end;

  begin
    work;
    for i := 0 to 9 do
      writeln(i, ': ', mytable[i]);
  end.

----------
Measurement is not management.

RE: Arrays - Assembly x86

Oh, and the target of the source I posted is Turbo Pascal (16-bit ASM there).

----------
Measurement is not management.

RE: Arrays - Assembly x86

(OP)
Glenn9999,

Thank you.

Your post was very helpful.

RE: Arrays - Assembly x86

Found a little error:

CODE

CMP CX, 10              { is CX = 10? }

This line should be:

CODE

CMP CX, 9              { is CX = 9? }

The error is shown by the loop taking the addressing past the table into the next variable.  You can see that by writing i before the loop and having it be 20 (10*2), which makes sense when you look at i in binary form.

----------
Measurement is not management.

RE: Arrays - Assembly x86

(OP)
Glenn9999,

Thank you for the correction. Can you help me convert an If statement to assembly language.

The if statement is:

if (value > 100) and (count <= 10)
then
     subtract 5*count from value;
end if;

This is what I have:

cmp value, 100
jne
cmp ecx, 10
jl
mov edx

This is where I left off. Can you help me with this

RE: Arrays - Assembly x86

Turbo Pascal (16-bit ASM) again.  On the jump comparison you have to give it a place to jump to, so I negated the logic.  The logic as it is does short-circuit evaluation as well, so it'll change a bit if you want both values evaluated regardless.

CODE

program ifstmt;
  var
    count, value: integer;
    orig_value: integer;

  procedure work_asm; assembler;
    label
      end_jump;
    asm
      CMP    value, 100  { compare value with 100 }
      JLE    end_jump    { go to end if value <= 100 }
      CMP    count, 10   { compare count with 10 }
      JG     end_jump    { go to end if count > 10 }

      MOV    AX, count   { ax := count }
      MOV    BX, value   { bx := value }
      MOV    CX, 5       { cx := 5 - can not do operation on constant }
      MUL    CX          { AX := ax * cx }
      SUB    BX, AX      { BX := BX - AX }
      MOV    Value, BX   { value := BX }
      end_jump:
    end;

  procedure pas_work;
    begin
      if (value > 100) and (count <= 10) then
        value := value - (5*count);
    end;

  begin
    writeln('Count <= 10 and value > 100 for value to change');
    writeln;
    write('Value: ');
    readln(value);
    write('Count: ');
    readln(count);
    orig_value := value;
    pas_work;
    writeln('PAS Value is now: ', value);
    value := orig_value;
    work_asm;
    writeln('ASM Value is now: ', value);
  end.

Hope this helps.  And hopefully for learning a few things myself in writing this that there aren't any bugs in it that I haven't already corrected.

Glenn

----------
Measurement is not management.

RE: Arrays - Assembly x86

(OP)
Glenn,

Thank you again for your help.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close