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
  • source code
  • Explanation
  • Code Explanation
  • Example

Was this helpful?

Edit on GitHub

Changing and Displaying Names in Assembly

source code

section .text
   global _start    ; Declare global entry point _start
_start:             ; Program entry point
   
   ; Writing the name 'AAA BBB'
   mov   edx, 9     ; Message length
   mov   ecx, name  ; Message to write
   mov   ebx, 1     ; File descriptor (stdout)
   mov   eax, 4     ; System call number (sys_write)
   int   0x80       ; Call kernel
   
   mov   [name], DWORD 'CCC'  ; Change the name to CCC BBB
   
   ; Writing the name 'CCC BBB'
   mov   edx, 8     ; Message length
   mov   ecx, name  ; 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

section .data
name db 'AAA BBB'   ; Initial name 'AAA BBB'

Explanation

This assembly code demonstrates the manipulation and display of names using system calls on a Linux platform. The code initializes a name as 'AAA BBB', changes it to 'CCC BBB', and then outputs both versions of the name. It leverages Linux syscalls to write the names to the standard output.

Code Explanation

  1. The data segment (section .data) contains the initial name 'AAA BBB' stored in memory.

  2. The text segment (section .text) begins with the global declaration _start, indicating the entry point for the linker.

  3. The code uses the mov instruction to set up syscalls for writing and to initialize the name 'AAA BBB'.

  4. The first mov instruction sets up a syscall to write 'AAA BBB' to the standard output. The registers are set as follows:

    • edx: Length of the message (9)

    • ecx: Address of the message (name)

    • ebx: File descriptor for standard output (1)

    • eax: Syscall number for sys_write (4)

    • int 0x80: Invokes the kernel to execute the syscall

  5. The code then changes the name to 'CCC BBB' by overwriting the memory location of the name using the mov instruction.

  6. The second mov instruction sets up another syscall to write the modified name 'CCC BBB' to the standard output. The registers are similarly configured.

  7. Finally, the code uses syscalls to exit the program (eax set to 1) and ends the _start section.

Example

Suppose you assemble and run this code on a Linux system. The output displayed will be:

AAA BBB
CCC BBB

This example illustrates how assembly language can be employed to manipulate and output text data, showcasing the process of changing and displaying names using basic syscalls.

PreviousAssembly Program: Demonstrating Loop and TestingNextSelection Sort from Minimum to Maximum

Last updated 1 year ago

Was this helpful?