Hello and welcome to dooseep.
About dooseep - dooseep is an online learning and education platform. Its owner is Prahlad Godara.
Dooseep provides seamless easy learning and other knowledge with detailed, clear and to-the-point content on technical and non-technical topics.
Memory management is the process of controlling and coordinating a computer's main memory. It ensures that blocks of memory space are properly managed and allocated so the operating system (OS), applications and other running processes have the memory they need to carry out their operations.
As part of this activity, memory management takes into account the capacity limitations of the memory device itself, deallocating memory space when it is no longer needed or extending that space through virtual memory. Memory management strives to optimize memory usage so the CPU can efficiently access the instructions and data it needs to execute the various processes.
In assembly language you can use both static and dynamic memory allocation. By properly managing the process of memory allocation, reallocation and deallocation, large programs can run efficiently even with limited memory.
The assembly language me Sys_brk() system call is provided by the kernel, in order to allocate memory without the need to move it later. This call allocates memory right behind the application image in memory. This system function allows you to set the highest available address in the data section.
This system call takes one parameter, which is the highest memory address needed to be set. This value is stored in the EBX register.
In case of any error, sys_brk() returns -1 or returns the negative error code itself. The following example demonstrates dynamic memory allocation.
Exampal
The following program allocates 16kb of memory using the sys_brk() system call −
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
mov eax, 45 ;sys_brk
xor ebx, ebx
int 80h
add eax, 16384 ;number of bytes to be reserved
mov ebx, eax
mov eax, 45 ;sys_brk
int 80h
cmp eax, 0
jl exit ;exit, if error
mov edi, eax ;EDI = highest available address
sub edi, 4 ;pointing to the last DWORD
mov ecx, 4096 ;number of DWORDs allocated
xor eax, eax ;clear eax
std ;backward
rep stosd ;repete for entire allocated area
cld ;put DF flag to normal state
mov eax, 4
mov ebx, 1
mov ecx, msg
mov edx, len
int 80h ;print a message
exit:
mov eax, 1
xor ebx, ebx
int 80h
section .data
msg db "Allocated 16 kb of memory!", 10
len equ $ - msg
Tags- Nasm Assembly language Memory Management. what is Memory Management in assembly language, This blogcreates content similar to stackoverflow geeks for geeks tutorialspoint w3schools and dooseep,Memory Management in assembly in hindi
File management in assembly language is used to organize data and files available on your device,
modify them like create new files, edit, delete, modify, move, rename, read, write etc.
The system treats any input or output data as a stream of bytes. There are three standard file streams -
Standard input (stdin),
Standard output (stdout), and
Standard error (stderr).
File descriptor and file pointer are used to write commands in file handler.
file descriptor - When a new file is created or an existing file is opened, the file descriptor is used to access the file. File descriptor is a 16-bit integer assigned to a file as a file ID.
The file descriptors of standard file streams - stdin, stdout and stderr are 0, 1 and 2 respectively.
file pointer - A file pointer specifies a location in a file for subsequent read/write operations, in terms of bytes. Each file is treated as a sequence of bytes. Each open file is associated with a file pointer that specifies an offset in bytes relative to the beginning of the file. When a file is opened, the file pointer is set to null.
File Handling System Calls
The following table briefly describes the system calls related to file handling −
%eax
Name
%ebx
%ecx
%edx
2
sys_fork
struct pt_regs
-
-
3
sys_read
unsigned int
char *
size_t
4
sys_write
unsigned int
const char *
size_t
5
sys_open
const char *
int
int
6
sys_close
unsigned int
-
-
8
sys_creat
const char *
int
-
19
sys_lseek
unsigned int
off_t
unsigned int
The steps required for using the system calls are same, as we discussed earlier −
Put the system call number in the EAX register.
Store the arguments to the system call in the registers EBX, ECX, etc.
Call the relevant interrupt (80h).
The result is usually returned in the EAX register.
Creating and Opening a File
For creating and opening a file, perform the following tasks −
Put the system call sys_creat() number 8, in the EAX register.
Put the filename in the EBX register.
Put the file permissions in the ECX register.
The system call returns the file descriptor of the created file in the EAX register, in case of error, the error code is in the EAX register.
Opening an Existing File
For opening an existing file, perform the following tasks −
Put the system call sys_open() number 5, in the EAX register.
Put the filename in the EBX register.
Put the file access mode in the ECX register.
Put the file permissions in the EDX register.
The system call returns the file descriptor of the created file in the EAX register, in case of error, the error code is in the EAX register.
Among the file access modes, most commonly used are: read-only (0), write-only (1), and read-write (2).
Reading from a File
For reading from a file, perform the following tasks −
Put the system call sys_read() number 3, in the EAX register.
Put the file descriptor in the EBX register.
Put the pointer to the input buffer in the ECX register.
Put the buffer size, i.e., the number of bytes to read, in the EDX register.
The system call returns the number of bytes read in the EAX register, in case of error, the error code is in the EAX register.
Writing to a File
For writing to a file, perform the following tasks −
Put the system call sys_write() number 4, in the EAX register.
Put the file descriptor in the EBX register.
Put the pointer to the output buffer in the ECX register.
Put the buffer size, i.e., the number of bytes to write, in the EDX register.
The system call returns the actual number of bytes written in the EAX register, in case of error, the error code is in the EAX register.
Closing a File
For closing a file, perform the following tasks −
Put the system call sys_close() number 6, in the EAX register.
Put the file descriptor in the EBX register.
The system call returns, in case of error, the error code in the EAX register.
Updating a File
For updating a file, perform the following tasks −
Put the system call sys_lseek () number 19, in the EAX register.
Put the file descriptor in the EBX register.
Put the offset value in the ECX register.
Put the reference position for the offset in the EDX register.
The reference position could be:
Beginning of file - value 0
Current position - value 1
End of file - value 2
The system call returns, in case of error, the error code in the EAX register
Exampal
The following program creates and opens a file named myfile.txt, and writes a text 'Welcome to Dooseep.com' in this file. Next, the program reads from the file and stores the data into a buffer named info. Lastly, it displays the text as stored in info. −
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
;create the file
mov eax, 8
mov ebx, file_name
mov ecx, 0777 ;read, write and execute by all
int 0x80 ;call kernel
mov [fd_out], eax
; write into the file
mov edx,len ;number of bytes
mov ecx, msg ;message to write
mov ebx, [fd_out] ;file descriptor
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
; close the file
mov eax, 6
mov ebx, [fd_out]
; write the message indicating end of file write
mov eax, 4
mov ebx, 1
mov ecx, msg_done
mov edx, len_done
int 0x80
;open the file for reading
mov eax, 5
mov ebx, file_name
mov ecx, 0 ;for read only access
mov edx, 0777 ;read, write and execute by all
int 0x80
mov [fd_in], eax
;read from file
mov eax, 3
mov ebx, [fd_in]
mov ecx, info
mov edx, 26
int 0x80
; close the file
mov eax, 6
mov ebx, [fd_in]
int 0x80
; print the info
mov eax, 4
mov ebx, 1
mov ecx, info
mov edx, 26
int 0x80
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
file_name db 'myfile.txt'
msg db 'Welcome to Dooseep.com'
len equ $-msg
msg_done db 'Written to file', 0xa
len_done equ $-msg_done
section .bss
fd_out resb 1
fd_in resb 1
info resb 26
Tags- Nasm Assembly language file management. This blogcreates content similar to
stackoverflow geeks for geeks tutorialspoint w3schools and dooseep,file handling in assembly in hindi
Macros: A macro is a set of instructions that is defined once and can then be used multiple times in a program. If instructions have to be used repeatedly for a particular task, a code block is made of a group of those instructions which are called and used at the time of need. This is called macros.
Another way to ensure modular programming in assembly language is to write macros. A macro is a sequence of instructions, which is specified by a name and can be used anywhere in the program.
macro Syntax
In NASM, macros are defined with the %macro and %endmacro directives. Macros begin with the %macro directive and end with the %endmacro directive.
Syntax for macro definition -
%macro macro_name number_of_params
macro body
%endmacro
Where, number_of_params specifies the number of parameters, macro_name specifies the name of the macro.
The macro is invoked using the macro name with the required parameters. When you need to use some sequence of instructions many times in a program, you can put those instructions in a macro and use it instead of typing the instructions every time.
For example, a very common requirement for programs is to write a string of characters to the screen. To display a string of characters, you need the following sequence of instructions −
mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
In the above example of displaying a character string, the registers EAX, EBX, ECX, and EDX are used by the INT 80H function call. Therefore, every time you need to display on the screen, you need to save these registers on the stack, invoke INT 80H, and then restore the original value of the registers from the stack. Therefore, it may be useful to write two macros to save and restore the data.
We have seen that, some instructions like IMUL, IDIV, INT, etc require some information to be stored in some specific registers and even return values in some specific registers. If the program was already using those registers to hold important data, the existing data in these registers must be saved to the stack and restored after the instruction is executed.
Macros Exampal
The following example shows how to define and use macros −
; A macro with two parameters
; Implements the write system call
%macro write_string 2
mov eax, 4
mov ebx, 1
mov ecx, %1
mov edx, %2
int 80h
%endmacro
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
write_string msg1, len1
write_string msg2, len2
write_string msg3, len3
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
msg1 db 'Hello, programmers!',0xA,0xD
len1 equ $ - msg1
msg2 db 'Welcome to the world of,', 0xA,0xD
len2 equ $- msg2
msg3 db 'Linux assembly programming! '
len3 equ $- msg3
result −
Hello, programmers!
Welcome to the world of,
Linux assembly programming!
Tags- Nasm Assembly language Macros in hindi. This blogcreates content similar to stackoverflow geeks for geeks tutorialspoint w3schools and dooseep,macro in assembly
Ciranjeevi bna hi ya nahin kaise pata karen | How to see name in chiranjeevi yojana.
Under the Chiranjeevi Health Insurance Scheme, poor families are given free treatment. According to this scheme,
there is a provision to provide health insurance cover to all the citizens of the state. After the introduction of
the Chiranjeevi Health Scheme, treatment up to Rs 10 lakh was provided free of cost in private hospitals.
How to know whether the name is linked in Chiranjeevi Yojana?
It is necessary for the Jan Aadhaar card holder to make sure that Jan Aadhaar Card is active or inactive in
Chiranjeevi Yojana Status. To check, you go to the official website and enter the Jan Aadhaar card number and
submit.
Scroll down to the bottom of the website home page.
Enter your Jan Aadhaar Card Number
Status will be on the screen in front of you.
Beneficiaries associated with Chiranjeevi Yojana should check their name in the same way. Name check can be
done easily on the basis of Jan Aadhaar card. The above process is very easy. If Eligibility / Yes is written in
Jan Aadhaar Card Status. So you are the beneficiary of Chiranjeevi Yojana.
Chiranjeevi yojana Related Question Answer
How to see your name in Chiranjeevi Yojana?
To see your name in Chiranjeev Yojana, open the government's website chiranjeevi.rajasthan.gov.in. After
this, enter your Jan Aadhaar number in the box below Search Enrollment Status. Then select the Search button.
After this the eligibility status will open in front of you.
Who is eligible for Chiranjeevi Yojana?
Under this scheme, the state government gives benefits only to the permanent residents of Rajasthan. Families
living below the poverty line and getting logistics on the Rasan card get its benefit for free.
How much does it cost to join Chiranjeevi Yojana?
Under the Chief Minister Chiranjeevi Health Insurance Scheme, cashless insurance of five lakh rupees will be
given to each family of the state. In this, the economically poor will get this insurance without any premium.
While all other families will have to pay an annual premium of Rs 850 to take advantage of the scheme.
Registration will have to be done to join the scheme.
Who can get the benefit of Chiranjeevi Yojana?
If someone wants to take advantage of this scheme, then for this a Jan Aadhaar card made in the name of the
female head of the family is required. If you have a Jan Aadhaar card, then with the help of this you are able
to apply for the scheme to the family through e-friend or through online.
Which diseases are covered under Chiranjeevi Yojana?
(Chiranjeevi Yojana Bimariyan suchi) The state government is providing about 1597 health packages free of
cost under the Chiranjeevi Yojana. Which includes serious diseases like Kovid-19, Black Fungus, Cancer,
Paralysis, Heart Surgery, Neuro Surgery, Organ Transplant etc.
What is needed to make Chiranjeevi card?
By opening the government's website health.rajasthan.gov.in, you can apply for the Chiranjeevi scheme sitting
at home. What are the documents required to add name in Chiranjeevi Yojana? Aadhaar Card, Ration Card, Bank
Account Passbook, Mobile Number, Passport Size Photo, Residence Certificate, Email ID to add name in
Chiranjeevi Yojana.
In how many days Chiranjeevi card is made?
Chiranjeevi Card is implemented within 48 hours of your application. But it may take 15 - 30 days to receive
the original passport. After the Chiranjeevi card application is approved, you get its number linked to your
Janadhar card. And you can take advantage of it.
What is chiranjeevi scheme status 200.
Chiranjeevi yojana status 200 means your eligibility code is visible to all.
How to check Chiranjeevi scheme status?
It is necessary for the Jan Aadhaar Card holder to make sure that the Jan Aadhaar card is active under the
scheme or not, for this visit the official website. Scroll down and enter the Jan Aadhaar card number and
click on the Verify option. Whatever the status is, it will appear in front of you.
In assembly language, when any code block or instruction group has to be used repeatedly, then recursion is used. Recursion occurs when a function or instruction group repeatedly calls itself, directly or indirectly.
There are two types of recycling: direct and indirect.
direct recursion - In direct recursion, the process calls itself.
indirect recursion - in indirect recursion, the first process calls the second process, which in turn calls the first process.
Recursion can be seen in many mathematical algorithms. For example, consider the case of computing the factorial of a number. The factorization equation of a number is given by
Fact (n) = n * fact (n-1) for n > 0
Recursion Exampal
For example: The factorial of 5 is the factorial of 1 x 2 x 3 x 4 x 5 = 5 x 4 and this can be a good example to show a recursive process. Every recursive algorithm must have a termination condition, that is, the recursive calling of the program must stop when a condition is met. In the case of the factorial algorithm, the final condition is reached when n is 0.
Example
The following program shows how to implement factorial n in assembly language. To keep the program simple, we'll calculate the factorial of 3.
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
mov bx, 3 ;for calculating factorial 3
call proc_fact
add ax, 30h
mov [fact], ax
mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov edx,1 ;message length
mov ecx,fact ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
proc_fact:
cmp bl, 1
jg do_calculation
mov ax, 1
ret
do_calculation:
dec bl
call proc_fact
inc bl
mul bl ;ax = al * bl
ret
section .data
msg db 'Factorial 3 is:',0xa
len equ $ - msg
section .bss
fact resb 1
Tags- Nasm Assembly language Arrays in hindi. This blogcreates content similar to stackoverflow geeks for geeks tutorialspoint w3schools and dooseep,Recursion in ansm assembly
CPU is the most important part used in the working of computer. CPU only does all the processing of data in the computer. If you open more programs or application software simultaneously, the cpu will have to work a lot and the cpu will reach its high limit of 100% usage. Other than that bad program. Loop Work. Due to malware etc also the cpu reaches to the high limit.
Windows High CPU Usage: Why is my CPU at 100/99/90…?
First of all you should know what are the reasons for 100% CU Usage on laptop and pc. Here are the main reasons:
background apps - There are a lot of background apps running on your Windows 11 computer. Normally, you don't use these background apps. But if they are running in the background, they will occupy your CPU usage. This may be the reason for the high CPU usage of Windows.
virus or malware - Your computer is infected with a virus or malware. If your computer has viruses or malware, they will not only damage your files but also bring high CPU usage on your Windows 11 device.
Windows Services - Windows Services are using your CPU. It is not only the apps that are using your computer's CPU, but Windows services as well. Sometimes, a Windows service may require excessive demand of your CPU for a short period of time. This can result in high CPU usage on your computer.
Antivirus software - Antivirus software is using excessive CPU. To protect your computer from viruses, you might have installed third-party anti-virus software on your device. Usually, you can set the software to run in the background. Sometimes, background scanning can overload the CPU, which leads to high CPU usage in Windows.
If you are running multiple apps at the same time. Or you are playing high-end games. Similar other processor-intensive apps are running simultaneously. So cpu can reach 100% usage.
How to check CPU usage on Windows?
Checking the CPU usage on your Windows 11 computer is very simple. You can do this using Task Manager.
Right-click on the Start button from the taskbar and choose Task Manager from the WinX menu to open Task Manager. You can also open it by searching task manager in window search.
If you see only some running programs, click More details.
Under Processes, you can see the CPU usage of your device.
How to fix 100% or higher CPU usage on Windows?
Let's summarize some of the ways to solve this problem on Windows 10, 11 and detail them in this section. you can try them to see
Reboot your computer -reboot your computer
Restart your computer can close all running apps and services at once. After rebooting the computer, you can go into Task Manager to check if CPU usage is still high. If not, you can use your PC normally. Please remember this time: You'd better not open too many apps. When you don't need to use an app, you should close it, but don't minimize it.
Close unnecessary apps - If your Windows CPU usage is high again, then you need to check if some unnecessary apps are currently running and close them to free up more CPU.
All you need to do is :
Open Task Manager on your computer.
Click on More Details to continue.
In the CPU column under Processes, you can see the CPU usage status on your device. You can click the CPU column to have Task Manager show CPU usage in descending order. Then, you can close unnecessary apps that are consuming too much CPU. All you need to do is right-click on the app you want to close and select End Task from the right-click menu. You can also select the target app and then click on the End Task button at the bottom right corner to close it. After that, you can repeat this step to close all unnecessary apps and reduce CPU usage.
Disable Unnecessary Startup Apps - Some apps start when your computer boots. These are the startup apps. Typically, these apps are the tools you use most often. Although some apps are set to start on computer boot when installed, you may not have noticed this issue. If you have multiple apps running on your computer at the same time, the CPU usage will be high. To solve the problem, you can disable startup apps that you do not use often
Update Windows to the latest version - High CPU usage may be a bug on your Windows computer. If Microsoft finds it, it will find a fix in an optional update or a major update and release the fix. So it is better that you keep your Windows up to date.
You can visit Windows Update to check for available updates for Windows:
Go to Start > Settings > Windows Update.
Click on the Check for Updates button to see if an update is available. If yes, the update will be downloaded and installed on your computer.
If necessary, you must restart your computer to complete the entire installation process.
Disable Windows Update Service - Windows Update can automatically scan for updates and download and install updates on your computer. This will definitely use CPU and increase CPU usage. If CPU usage is too high, you can open Task Manager to see if Windows Update is using too much CPU. If yes, then you can disable Windows Update service to solve high CPU usage issue on Windows
Click on the Search icon from the taskbar and search for Services.
Select the first result to open Services on Windows
Scroll down to find Windows Update option, then click on it to open its Properties interface.
Expand Startup types and select Disabled.
Click on Apply.
Click OK.
Scan your computer for viruses and malware - Viruses and malware are major threats to your computer. They can steal your confidential information. They can also use a lot of CPU, even 100% CPU usage on Windows 11.
Therefore, if all the above methods can't help you fix the high CPU usage problem, you can use anti-virus software to scan for viruses and malware, and remove them when found .
Therefore, if all the above methods can't help you fix the high CPU usage problem, you can use anti-virus software to scan for viruses and malware, and remove them when found
Therefore, if all the above methods can't help you fix the high CPU usage problem, you can use anti-virus software to scan for viruses and malware, and remove them when found .
Uninstall third-party anti-virus software - Some third-party anti-virus programs are set to run in the background to scan for viruses and malware. But they may cause high CPU usage. You can go into Task Manager to check if your third-party software is using too much CPU in the background. If yes, then you can uninstall it from your computer. Some users worry about virus and malware problem after uninstalling third-party anti-virus software. This is not a problem because Windows has built-in anti-virus software: Windows Defender. This tool can provide real-time protection for your device if it is enabled.
Disable Background Apps - Apps running in the background are also using the CPU on your device. If you want to reduce CPU usage, you can choose to disable unnecessary background apps.
Go to Start > Settings > Apps.
Select Apps & features from the right panel.
Find the app you want to stop from running in the background, then click on the 3-dot menu next to it and select Advanced options.
Expand the options under Background apps permissions and select Never.
Power Option - Some power settings can reduce your CPU speed. Power issues are familiar to laptop users, but they can affect desktop systems as well. Check your power options by clicking the Start menu and typing "edit power plan". Once it's open, click on "Power Options" in the address bar at the top of the window. Click "Show additional plans", then enable a non-power saver plan.
update drivers - If a process is still using a lot of CPU, outdated or sub-optimal drivers may be to blame. Drivers are programs that control specific devices connected to your motherboard. Updating your drivers can eliminate compatibility issues or bugs that cause increased CPU usage.
Is it abnormal to have 100% cpu usage?
Many people have a question in their mind. Sometimes the cpu is 100% other times it is normal I don't know what to do.
Sometimes it is normal for cpu to be 100% when there is a long task or heavy program run then cpu reaches 100% usage. If you are not running anything yet your computer or laptop runs at 100% and becomes slow or crashed or cpu is always above 100 or 90% then you have to fix this problem.
Conclusion -CPU 100% usage in computer or laptop is due to using more apps simultaneously, running bad programs, malware, bad or outdated drivers etc. You can fix this problem by closing background apps, removing bad programs, updating your windows and rebooting, and updating drivers.
Tags- how to fix windows laptop computer 100% usage cpu long time ,cpu 100 usage windows 11
cpu 100 percent usage,
cpu usage 100 percent windows 10 fix ,
how to fix cpu 100 percent usage,
cpu 100% usage fix.
100% cpu usage windows 10,
cpu 100 usage windows 8,
cpu 100 usage when gaming,
cpu usage 100 nothing running,
how to fix high cpu usage,
why is my cpu usage so high with nothing running,
high cpu usage windows 10
Procedures are a small part of a larger project such that assembly code is usually larger in size. In this, to understand and manage the code properly, the entire code is divided according to different tasks. Only a group of small instructions made according to these different tasks are called Procedures.
What are procedures in assembly language?
To make assembly code more modular, readable and smaller in size, we use procedures. Processes are very similar to tasks, as each process performs a specific task.
Procedures or subroutines are very important in assembly language, as the assembly language programs tend to be large in size. Procedures are identified by a name. Following this name, the body of the procedure is described which performs a well-defined job. End of the procedure is indicated by a return statement.
Syntax
proc_name:
procedure body
...
ret
The procedure is called from another function using the CALL instruction. The CALL instruction must have the name of the called procedure as an argument as shown below -
CALL proc_name
The called process returns control to the calling process using the RET instruction.
Example
Let us write a very simple procedure named sum that adds the variables stored in the ECX and EDX register and returns the sum in the EAX register −
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
mov ecx,'4'
sub ecx, '0'
mov edx, '5'
sub edx, '0'
call sum ;call sum procedure
mov [res], eax
mov ecx, msg
mov edx, len
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov ecx, res
mov edx, 1
mov ebx, 1 ;file descriptor (stdout)
mov eax, 4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
sum:
mov eax, ecx
add eax, edx
add eax, '0'
ret
section .data
msg db "The sum is:", 0xA,0xD
len equ $- msg
segment .bss
res resb 1
When the above code is compiled and executed, it produces the following result −
The sum is: 9
Stacks Data Structure - Example
A stack is an array-like data structure in the memory in which data can be stored and removed from a location called the 'top' of the stack. The data that needs to be stored is 'pushed' into the stack and data to be retrieved is 'popped' out from the stack. Stack is a LIFO data structure, i.e., the data stored first is retrieved last.
Assembly language provides two instructions for stack operations: PUSH and POP. These instructions have syntaxes like −
PUSH operand
POP address/register
The memory space reserved in the stack segment is used for implementing stack. The registers SS and ESP (or SP) are used for implementing the stack. The top of the stack, which points to the last data item inserted into the stack is pointed to by the SS:ESP register, where the SS register points to the beginning of the stack segment and the SP (or ESP) gives the offset into the stack segment.
The stack implementation has the following characteristics −
Only words or doublewords could be saved into the stack, not a byte.
The stack grows in the reverse direction, i.e., toward the lower memory address
The top of the stack points to the last item inserted in the stack; it points to the lower byte of the last word inserted.
As we discussed about storing the values of the registers in the stack before using them for some use; it can be done in following way −
; Save the AX and BX registers in the stack
PUSH AX
PUSH BX
; Use the registers for other purpose
MOV AX, VALUE1
MOV BX, VALUE2
...
MOV VALUE1, AX
MOV VALUE2, BX
; Restore the original values
POP BX
POP AX
Example
The following program displays the entire ASCII character set. The main program calls a procedure named display, which displays the ASCII character set.
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
call display
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
display:
mov ecx, 256
next:
push ecx
mov eax, 4
mov ebx, 1
mov ecx, achar
mov edx, 1
int 80h
pop ecx
mov dx, [achar]
cmp byte [achar], 0dh
inc byte [achar]
loop next
ret
section .data
achar db '0'
When the above code is compiled and executed, it produces the following result
Tags- Nasm Assembly language Arrays in hindi. This blogcreates content similar to stackoverflow geeks for geeks tutorialspoint w3schools and dooseep,Procedures and Stacks Data Structure