How to resolve the algorithm Arrays step by step in the X86 Assembly programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Arrays step by step in the X86 Assembly programming language

Table of Contents

Problem Statement

This task is about arrays. For hashes or associative arrays, please see Creating an Associative Array. For a definition and in-depth discussion of what an array is, see Array.

Show basic array syntax in your language. Basically, create an array, assign a value to it, and retrieve an element   (if available, show both fixed-length arrays and dynamic arrays, pushing a value into it). Please discuss at Village Pump:   Arrays.
Please merge code in from these obsolete tasks:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Arrays step by step in the X86 Assembly programming language

Source code in the x86 programming language

section .text
	global _start
	
	_print:
		mov ebx, 1
		mov eax, 4
		int 0x80
		ret
		
	_start:
		;print out our byte array. ergo, String.
		mov edx, sLen
		mov ecx, sArray
		call _print
		mov edx, f_len
		mov ecx, f_msg
		call _print
		mov edx, 6			;our array members length.
		xor ecx, ecx
		mov ecx, 4
		;turnicate through the array and print all it's members.
		;At an offset of *4, each array member is referenced
		;at 1,2,3 and so on. 
		_out_loops:
			push ecx
			mov ecx, [fArray+esi*4]
			call _print
			inc esi
			pop ecx
		loop _out_loops
		mov edx, u_len
		mov ecx, u_msg
		call _print
		;Let's populate 'uArray' with something from sArray.
		;mov edi, uArray
		mov ecx, 4
		xor esi, esi
		_read_loops:	
			push dword [fArray+esi*4]
			pop dword [uArray+esi*4]
			inc esi
		loop _read_loops
		mov ecx, 4
		xor esi, esi
		_out_loops2:
			push ecx
			mov ecx, [uArray+esi*4]
			call _print
			inc esi
			pop ecx
		loop _out_loops2
		push 0x1
		mov eax, 1
		push eax
		int 0x80
		
section .data
sArray	db 'a','r','r','a','y','s',' ','a','r','e',' ','f','u','n',0xa
sLen		equ $-sArray

crap1		db "crap1",0xa
crap2		db "crap2",0xa
crap3		db "crap3",0xa
crap4		db "crap4",0xa

fArray	dd crap1,crap2
	dd crap3,crap4

f_msg		db "fArray contents",0xa,"----------------------",0xa
f_len		equ $-f_msg
u_msg		db "uArray now holds fArray contents.. dumping..",0xa,"----------------------",0xa
u_len		equ $-u_msg

section .bss
uArray	resd 1
        resd 1
	resd 1
	resd 1

  

You may also check:How to resolve the algorithm Simple windowed application step by step in the R programming language
You may also check:How to resolve the algorithm Longest increasing subsequence step by step in the PowerShell programming language
You may also check:How to resolve the algorithm String prepend step by step in the Pascal programming language
You may also check:How to resolve the algorithm Brazilian numbers step by step in the Sidef programming language
You may also check:How to resolve the algorithm Unix/ls step by step in the C++ programming language