Author Topic: How can i put integer in 2x2 matrix?  (Read 4314 times)

Offline miskin

  • Jr. Member
  • *
  • Posts: 10
  • Country: de
  • use Linux mint 15 in VM
How can i put integer in 2x2 matrix?
« on: May 31, 2015, 01:54:33 AM »
it have to look like this with space between the numbers.i want to write it in a funktion as inline assambler.

3 5
23 24 7
8
1 122

thx

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2437
  • Country: us
Re: How can i put integer in 2x2 matrix?
« Reply #1 on: May 31, 2015, 02:51:47 PM »
Hi Miskin,

I don't see how a 2X2 matrix is going to look like what you show. You may need to explain more about what you're trying to do.

I understand you got the subtraction example working with some help from Shaynox, right? So you know how to print an integer? You know how to print a space? You know how to print a newline? Where do you run into the problem?

Some things you might want to think about...

Are you always going to want the matrix to be 2X2 or might you want to handle other sizes? Might you want to let the user specify number of rows and number of columns (this is tougher), or is a fixed size per program okay? Are you going to want to handle negative numbers? Might you want the numbers right-justified? (do you know how to do that with "printf"?) It isn't too clear from what you show just what you want it to look like...

Best,
Frank


Offline miskin

  • Jr. Member
  • *
  • Posts: 10
  • Country: de
  • use Linux mint 15 in VM
Re: How can i put integer in 2x2 matrix?
« Reply #2 on: May 31, 2015, 06:29:58 PM »
Hi,
it's a nxn matrix





     for(i=0;i<zeile;i++){
        fprintf(output,"%d:",i);
      for(j=0;j<spalte;j++){
         if(matrix[i/j]!=0)   
         fprintf(output," %d ",(int)matrix[i/j]); 
      }fprintf(output,"%s","\n");
   }

this puts the Numbers in the matrix
but before that i have to put them with a inline-assembler function in the matrix.
or i can put them in the matrix directly whit inline-assembler.
« Last Edit: May 31, 2015, 08:09:49 PM by miskin »

Offline shaynox

  • Full Member
  • **
  • Posts: 118
  • Country: fr
  • use Windows 10 x64
Re: How can i put integer in 2x2 matrix?
« Reply #3 on: May 31, 2015, 08:26:29 PM »
So you want to modify 2x2 matrix in asm ?

Then use matrix[] array by put brackets around matrix label, you should declare matrix array outside of functions (global) for better using of variables by their name instead their offset in stack (esp + .. ).

Ex:
Code: [Select]
asm("mov    [matrix + eax], dword 2");
« Last Edit: May 31, 2015, 08:32:09 PM by shaynox »
Basic asm standard:
reg(lowercase) - instruction(lowercase) -> instruction     dest, src

Offline miskin

  • Jr. Member
  • *
  • Posts: 10
  • Country: de
  • use Linux mint 15 in VM
Re: How can i put integer in 2x2 matrix?
« Reply #4 on: June 02, 2015, 11:18:26 AM »
Hi,
yes the matrix is now global.
the variable a_asm have the line of my matrix[line][] and b_asm have the number to put in.
The problem is how can i get the right column and the space between the numbers
for example:
int inlineAddition(0,4)   -->   0: 4
int inlineAddition(0,6)   -->   0: 4 6
int inlineAddition(1,17)   -->   0: 4 6
                                          1: 17
int inlineAddition(0,15)   -->   0: 4 6 15
                                          1: 17
......


int inlineAddition(int a_asm,int b_asm) {
        //a_asm = a;
   //b_asm = b;       
     __asm__ (".intel_syntax noprefix");
     __asm__ ("mov eax, [matrix + a_asm]");
     __asm__ ("add  eax,[b_asm]");
     __asm__ ("mov [c_asm], eax");
     __asm__ (".att_syntax noprefix");
      
    return c_asm;
}
« Last Edit: June 02, 2015, 11:31:34 AM by miskin »

Offline shaynox

  • Full Member
  • **
  • Posts: 118
  • Country: fr
  • use Windows 10 x64
Re: How can i put integer in 2x2 matrix?
« Reply #5 on: June 02, 2015, 11:40:13 AM »
Hi,

For select column, you just need to add equation like:

Code: [Select]
select_line * max_element_line + select_column or y * max_x + x


It's for display space while show matrix ? so just add space in printf.

Basic asm standard:
reg(lowercase) - instruction(lowercase) -> instruction     dest, src

Offline miskin

  • Jr. Member
  • *
  • Posts: 10
  • Country: de
  • use Linux mint 15 in VM
Re: How can i put integer in 2x2 matrix?
« Reply #6 on: June 02, 2015, 12:08:03 PM »
Hi,
how can i show the register ?
i need to see what happen in the eax, ebx ......
the multiplikation is in ecx is thath right?
thank you

Offline shaynox

  • Full Member
  • **
  • Posts: 118
  • Country: fr
  • use Windows 10 x64
Re: How can i put integer in 2x2 matrix?
« Reply #7 on: June 02, 2015, 12:17:33 PM »
If you want to show register, put in in variable, then show it.
Or use debugger, but I don't know how to use it.

The mul instruction use eax:
Code: [Select]
mov     eax, 2
mov     ebx, 3
mul     ebx          ; eax *= ebx
« Last Edit: June 02, 2015, 12:20:58 PM by shaynox »
Basic asm standard:
reg(lowercase) - instruction(lowercase) -> instruction     dest, src