Assembly Code Snippet
  • Assembly Code Snippet
  • Assembly Program: 4-Digit Decimal Number Addition
  • ASCII Division and Display in x86 Assembly
  • ASCII Arithmetic Addition in x86 Assembly
  • BCD Addition and Display in Assembly
  • BCD Arithmetic and Display in Assembly
  • Decimal Multiplication and Display in x86 Assembly
  • Assembly Program: Determining Endianness and Displaying Messages
  • Assembly Program: Determining Even and Odd Numbers
  • Assembly Program: Displaying Messages using Syscalls
  • Assembly Program: Finding and Printing the Largest Word in a Sentence
  • Assembly Program: Finding the Largest of Three Numbers
  • Displaying "Hello World!" in x86 Assembly
  • Increment and Display Digits in Assembly
  • Input and Display User Name in Linux Assembly
  • Input and Display User Number in Linux Assembly
  • Introduction to Linux Assembly Programming with Messages
  • Assembly Program: Demonstrating Loop and Testing
  • Changing and Displaying Names in Assembly
  • Selection Sort from Minimum to Maximum
  • Assembly Program: Sentence Word Deletion
  • Sum and Read Input Numbers:
  • Two-Digit Sum and Square - Assembly Program
  • Calculate and Display Sum
  • Sorting Numerical Elements (BubbleSort)
    • Assembly Program: Sorting Numerical Elements
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub

Assembly Program: Displaying Messages using Syscalls

This assembly program demonstrates how to display messages on the standard output using Linux syscalls. It prints two messages: one with a fixed message and another with a repeated word.

source code

; This assembly program displays messages using syscalls.

section .text
   global _start     ; Must be declared for linker (gcc)
	
_start:             ; Tell linker entry point
   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 to display message

   mov edx, 9        ; Message length
   mov ecx, s2       ; Message to write
   mov ebx, 1        ; File descriptor (stdout)
   mov eax, 4        ; System call number (sys_write)
   int 0x80          ; Call kernel to display message

   mov eax, 1        ; System call number (sys_exit)
   int 0x80          ; Call kernel to exit

section .data
msg db 'Displaying 9 stars', 0xa ; A message
len equ $ - msg    ; Length of the message
s2 times 6 db 'File'
``

## Code Explanation

The provided assembly code performs the following steps:

1. **Displaying the First Message**:
   - Initializes registers for syscall 4 (`sys_write`) to print the first message.
   - Calls the kernel to display the message "Displaying 9 stars" followed by a newline.

2. **Displaying the Second Message**:
   - Initializes registers for another syscall 4 to print the second message.
   - Prints the word "File" repeated 6 times without newline.

3. **Program Termination**:
   - Uses syscall 1 (`sys_exit`) to exit the program.

## Example

Upon running the program, you will see the following output:

Displaying 9 stars FileFileFileFileFileFile


In this example, the program uses syscalls to display the messages as described in the code.

## Usage

1. Ensure you are running this code on a Linux environment or emulator that supports the syscalls used in the code.
2. Assemble the code using an appropriate assembler (e.g., NASM) and linker (e.g., LD).
3. Run the assembled binary to execute the program.
4. Observe the output, which displays the messages using syscalls.

**Note**: Assembly language can interact with system components. Make sure you understand the code before running it, especially when it involves system calls.

---
PreviousAssembly Program: Determining Even and Odd NumbersNextAssembly Program: Finding and Printing the Largest Word in a Sentence

Last updated 1 year ago

Was this helpful?