I am new to assembly language and I'm using a simpler version called Y86, essentially the same thing. I wonder how to initialize a multidimensional array in such a format, specifically making a 2x2. Later with the 2x2 I will be adding two matrices (or arrays in this case). Thank you!
Multidimensional Array (2x2) Initialization in Assembly Language - Y86
1.5k Views Asked by Alowishious At
1
There are 1 best solutions below
Related Questions in ARRAYS
- Two different numbers in an array which their sum equals to a given value
- how to fill out the table with next values in array with one button
- How to sort a multi-dimensional array by the second array in descending order?
- Looping over defined array elements in Fortran
- Array appending after each onclick and loop in javascript
- PHP : How can I check Array in array?
- store numpy array in mysql
- Java Assign a Value to an array cell
- Saving FileSystemInfo Array to File
- Notice: Undefined offset: 1, but there is such offset
- How can I determine the index of the same set of characters between two strings that are of different lengths?
- Caused by: java.lang.ArrayIndexOutOfBoundsException: length=8; index=8
- Pull out first occurrences from array
- How to read a file then store to array and then print?
- C++ won't read in scientific notation data from a .txt file
Related Questions in ASSEMBLY
- (x64 Nasm) Writeline function on Linux
- Is the compiler Xcode uses to produce Assembly code a bad compiler?
- Why do we need AX instead of MOV DS, data directly with a segment?
- Bootloader in Assembly with Linux kernel
- How should the byte sequence 0x40 0x55 be interpreted by an x86-64 emulator?
- C++ code into assembly
- Drawing circles of increasing radius
- Assembly print on screen using pop ecx
- Equivalent to asm volatile in Gfortran?
- Show 640x480 BMP image with inline ASM c++
- Keep track of numbers entered in by a user in assembly
- 8086 Assembly Arrays with I/O
- DB ASM variable in Inline ASM C++
- What does Jump to means in callgrind?
- How to convert binary into decimal in assembly x8086?
Related Questions in Y86
- Y86 .long -5 being sent from memory to register as -1
- "can't find label" error in Y86 compiler
- Negating numbers in Y86
- No ouput displayed for unsigned multplication Y86
- Using Global Variables in Y86 Assembly
- Y86 Stopped in 1 Steps Exception HLT
- Trouble creating an array loop in Y86 Assembly
- Not getting output in first Y86 program
- Y86 program stops midway through throwing exception "Invalid instruction f4"
- Why is the wrong parameter being passed here?
- Is there a way to perform arithmetic right shift using only xorq, andq, addq, iaddq, & subq?
- List of y86 commands?
- Convert C function to Y86 function
- Implementing Y86 Fetch Instruction in C
- How to return void in y86
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
In machine code you have available (for information storage) CPU registers and memory.
Registers have fixed names and types and they are used like that, for example in x86 you can do
mov eax, 0x12345678to load 32b value into registereax.Memory is like continuous block of byte-cells, each having it's own unique physical address (like: 0, 1, 2, ... mem_size-1). So it is like 1 dimensional byte array.
Whatever different type you want, in the end it is somehow mapped to this 1D byte array, so you have to first design how that mapping happens.
Some mappings like for example 32 bit integers have native mappings/support in the instructions, so you can for example read whole 32b int by single instruction like
mov eax,[address], not having to compose it from individual bytes, but the CPU will for you read four bytes from memory at addresses:address+0,address+1,address+2andaddress+3and concatenate it into 32 bit value (on x86 CPU in little-endian order, so the byte fromaddress+0is in the lowest 8 bits of final value).Other mappings like "array 2x2" don't have native support, and you have to design the memory layout and write the code accordingly to support it. For 2 dimensional arrays often mapping
memory_offset = (row * columns_max + column) * single_element_byte_sizeis used.Like for 16x16 matrix of 32 bit floats you can calculate memory offset (from the start of matrix data, which is at offset 0):
But you are of course free to devise and implement any kind of mapping you wish...
edit: as Peter Cordes notes, some mappings favour certain task, like for example continuously designed matrices like the one above, in the task of adding two matrices, can be dealt with in the implementation as one dimensional 256 (16x16) element array, because there's no significance of row/columns in the matrix addition, so you can just add corresponding elements of both. In multiplication you have to traverse the elements in more complex patterns, where row/columns are important, so there you have to write more complex code to respect the 2D mapping logic.
edit 2, to actually add answer to your question:
Eee... this doesn't make sense from machine point of view. You simply need somewhere in memory reserved space, which represents data of the array, and you may want to set those to certain initial values, by simply writing those values into memory (by ordinary memory store instructions, like
mov [ebx],eax), or for example in simple code adding two matrices of fixed values, you can define both of them directly in.datasegment with some directive defining values, like for example in NASM assembler (for the simple mapping as described above):(check your assembler documentation to see which directives are available to reserve+initialize part of memory)
Which kind of memory area you want to reserve for the data (the load-time initialized
.data, or stack, or dynamically allocated from OS "heap", ...), and how you load it with initial data, is up to you, but in no way related to the "two dimensional array", usually the allocation/initialization code often works with all the types as "continuous block of bytes", without caring about the inner structure of the data, that's left for the other functions, which are dealing with particular elements of the data.