I made a code in assembly 8086. I load matrix (array) in memory with dimension 3x3. but this code works just for this dimension of matrix 3x3. Could someone give me an idea how could i make it to work with dimension m x n? the array is loaded in memory and at the end just print the result, another array. thanks
15 replies to this topic
#1
Posted 23 December 2011 - 01:58 PM
|
|
|
#2
Posted 23 December 2011 - 03:55 PM
Wrong forum,
Could you post your code? Is it all in assembly or is it a mixture and the function you wrote is in assembly?
Multi dimensional arrays as you would consider them in a language such as C where a 3x3 would look like
* * *
* * *
* * *
In memory when it's allocated actually looks like this
* * * * * * * * *
Handling it in assembly you'll basically have to handle the offsets yourself.
Here's a website with a graphic explanation
4.6 Multidimensional Arrays
Could you post your code? Is it all in assembly or is it a mixture and the function you wrote is in assembly?
Multi dimensional arrays as you would consider them in a language such as C where a 3x3 would look like
* * *
* * *
* * *
In memory when it's allocated actually looks like this
* * * * * * * * *
Handling it in assembly you'll basically have to handle the offsets yourself.
Here's a website with a graphic explanation
4.6 Multidimensional Arrays
"The best optimizer is between your ears" - Michael Abrash
Saying you can optimize a program is like saying you understand how a program works on every level of every facet on a specific machines configuration.
Saying you can optimize a program is like saying you understand how a program works on every level of every facet on a specific machines configuration.
#3
Posted 23 December 2011 - 04:58 PM
Sysop_fb said:
Wrong forum,
zemzela said:
I made a code in assembly 8086.
8086 assembly seems like it would go in the assembly forum.
* * *
As for the question, I would say you'd need to find a way to make the matrix size handling more dynamic, rather than assuming it's 3x3. You would also need to have a way to tell the code the dimensions, m and n, so that it can know the size. I don't think you can use the data size for that, unless it's a square matrix, because 3x2 and 2x3 would both have the same storage data size, but different dimensions.
So the next step would probably be writing the formulas and algorithms that you would use to calculate the offsets, and such, like Sysop_fb said, and then you would just need to work on entering the code that executes the algorithms.
#4
Posted 24 December 2011 - 01:18 AM
Could you post your code? It'd be a lot easier for us to help you if we could see what you're doing and how you're going about it. Please use the code tags when posting, by the way. Paste your code in, highlight it, and click the # button.
sudo rm -rf /
#5
Posted 24 December 2011 - 03:49 AM
; multi-segment executable file template.
data segment
matrix db 1, 2, 3, 4, 5, 6, 7, 8, 9 ; load matrix in memory
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
mov bx, matrix ; move matrix to offset bx
mov ch, 3
mov cl, 0
COLUMNAHEAD:
mov dl, [bx] ; get the first element of matrix in dl
add dl, 30h ; add to show number
mov ah, 02h
int 21h ; print first number
inc cl
cmp cl, ch ; compare if the counter is at the end of column
jge ROWAHEAD ; if greater go to row
add bx, 3 ; if not inc offset for 3
jmp COLUMNAHEAD
ROWAHEAD:
inc cl ; 1 element of roe
inc bx ; inc offset for one place
mov dl, [bx] ; get the number in dl
add dl, 30h ; convert to number
mov ah, 02h
int 21h ; print the number
cmp cl, 5
je COLUMNAHEAD
jne ROWAHEAD
COLUMNBACK:
inc cl
sub bx, 3
mov dl, [bx]
add dl, 30h
mov ah, 02h
int 21h
cmp cl, 7
jne COLUMNBACK
je ROWBACK
ROWBACK:
dec bx
mov dl, [bx]
add dl, 30h
mov ah, 02h
int 21h
JMP MIDDLE
MIDDLE:
add bx, 3
mov dl, [bx]
add dl, 30h
mov ah, 02h
int 21h
JMP END
END:
this is the code i wrote. it works for the matrix
1, 2, 3,
4, 5, 6,
7, 8, 9 and print 1, 4, 7, 8, 9, 6, 3, 2, 5
Matrix given in memory to print the spiral in opposite direction from clockwise (left column down the right lower range, right up column, a series of upper left, etc. until you get to the environment). This works just for dimension 3x3. this should works for mxn dimension. but i don't know how, any suggestion???
Edited by dargueta, 24 December 2011 - 01:18 PM.
#6
Posted 24 December 2011 - 01:25 PM
Dude, please use code tags. It makes your code easier for us to read, especially in C/C++ and such.
Anyway, are you going to get your dimensions from the terminal (i.e. have the user type them in) or are they going to be compile-time equ constants?
Anyway, are you going to get your dimensions from the terminal (i.e. have the user type them in) or are they going to be compile-time equ constants?
sudo rm -rf /
#7
Posted 24 December 2011 - 01:57 PM
i load my array in memory in the first line of code. i wrote the code with offset which will pass through the array and print just the number with offset given in condition. for example jump 3 numbers ant print the fourth. this works for the matrix 3x3 not for another dimension matrix for ex. 1,2,3,4,5,6,7,8,9,4,5 Thank you for your suggestions.
#8
Posted 24 December 2011 - 08:40 PM
You didn't answer my question, which is what I need to help you solve your problem.
sudo rm -rf /
#9
Posted 25 December 2011 - 01:33 AM
@zemzela: In other words, if m and n are the dimensions of the matrix, how, exactly, do you get the values for them?
Do you input them using a prompt box?:
Or do you ask for the dimensions via command line?:
Or maybe you read the dimensions from a file?:
Or how does the program know the dimensions of the matrix?
P.S. I didn't test any of the code above.
Do you input them using a prompt box?:
var m= parseInt (prompt ("Please enter the height of the matrix:"));
...
Or do you ask for the dimensions via command line?:
int m;
printf ("Please enter the height of the matrix: \r\n");
scanf ("%d", &m);
...
Or maybe you read the dimensions from a file?:
%define SIZEOF_OFSTRUCT ... main: enter 0, 0 sub esp, 8 sub esp, SIZEOF_OFSTRUCT sub esp, 4096 ;; [esp-4] = hFile ;; [esp-8] = integer () ;; [esp-(8 + SIZEOF_OFSTRUCT)] = the reopen buffer ;; [esp-(8 + SIZEOF_OFSTRUCT + 4096)] = read buffer push dword 0 lea eax, [ebp-(8 + SIZEOF_OFSTRUCT)] push dword eax call .over1 db "file01.txt", 0 .over1: call [OpenFile] mov dword [ebp-4], eax push dword 0 lea eax, [ebp-8] push dword eax push dword 4096 lea eax, [ebp-(8 + SIZEOF_OFSTRUCT + 4096)] push dword eax push dword [ebp-4] call [ReadFile] push dword [ebp-4] call [CloseHandle] .....
Or how does the program know the dimensions of the matrix?
P.S. I didn't test any of the code above.
#10
Posted 25 December 2011 - 09:39 PM
Just an FYI, zemzela is using MASM and RhetoricalRuvim is using NASM. Copying and pasting code won't quite work; you'll have to translate the directives like segment and ends.
sudo rm -rf /
#11
Posted 06 January 2012 - 05:47 AM
via command line.
The text of task is: Matrix given in memory to print the spiral in opposite direction from clockwise (left column down the right lower range, right up column, a series of upper left, etc. until you get to the middle)
The code must work for matrix with 4x3, 3x4, 5x5, etc. If you know help me with code in C++ or C. It is very important if you know, help me.
The text of task is: Matrix given in memory to print the spiral in opposite direction from clockwise (left column down the right lower range, right up column, a series of upper left, etc. until you get to the middle)
The code must work for matrix with 4x3, 3x4, 5x5, etc. If you know help me with code in C++ or C. It is very important if you know, help me.
#12
Posted 06 January 2012 - 12:00 PM
I wrote something like this once in JavaScript, but it's for clockwise, not counterclockwise; it's in another thread on CodeCall.
@dargueta: Is it considered doing the OP's homework if I post a link to the other thread that has that JavaScript code?
@dargueta: Is it considered doing the OP's homework if I post a link to the other thread that has that JavaScript code?
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top










