Difference between revisions of "CSC231 Copying Strings in RAM"
(Created page with "--~~~~ ---- =A Program with 2 Strings= <source lang="asm"> ;;; movString1s.asm ;;; D. Thiebaut ;;; ;;; ;;; ;;; To assemble, link, and run: ;;; nasm -f elf -F stabs movString1...") |
(→A Program with 2 Strings) |
||
Line 45: | Line 45: | ||
<br /> | <br /> | ||
<br /> | <br /> | ||
+ | =Copying msg1 into msg2, 1 byte at a time= | ||
+ | |||
+ | <br /> | ||
+ | <source lang="asm"> | ||
+ | ;;; movString1s.asm | ||
+ | ;;; D. Thiebaut | ||
+ | ;;; | ||
+ | ;;; This version copies msg1 to msg2 | ||
+ | ;;; | ||
+ | ;;; To assemble, link, and run: | ||
+ | ;;; nasm -f elf -F stabs movString1s.asm | ||
+ | ;;; ld -melf_i386 -o movStrings2 movStrings2.o | ||
+ | ;;; ./movStrings2 | ||
+ | ;;; | ||
+ | |||
+ | section .data | ||
+ | msg1 db "Smith College", 10 | ||
+ | msg1Len equ $-msg1 | ||
+ | msg2 db ".............", 10 | ||
+ | |||
+ | section .text | ||
+ | global _start | ||
+ | _start: | ||
+ | |||
+ | ;;; print msg1 | ||
+ | mov eax, 4 | ||
+ | mov ebx, 1 | ||
+ | mov ecx, msg1 | ||
+ | mov edx, msg1Len | ||
+ | int 0x80 | ||
+ | |||
+ | ;;; print original msg2 | ||
+ | mov eax, 4 | ||
+ | mov ebx, 1 | ||
+ | mov ecx, msg2 | ||
+ | mov edx, msg1Len | ||
+ | int 0x80 | ||
+ | |||
+ | ;;; copy msg1 into msg2 | ||
+ | mov al, byte [msg1] | ||
+ | mov byte[msg2], al | ||
+ | |||
+ | mov al, byte [msg1+1] | ||
+ | mov byte[msg2+1], al | ||
+ | |||
+ | mov al, byte [msg1+2] | ||
+ | mov byte[msg2+2], al | ||
+ | |||
+ | mov al, byte [msg1+3] | ||
+ | mov byte[msg2+3], al | ||
+ | |||
+ | mov al, byte [msg1+4] | ||
+ | mov byte[msg2+4], al | ||
+ | |||
+ | mov al, byte [msg1+5] | ||
+ | mov byte[msg2+5], al | ||
+ | |||
+ | mov al, byte [msg1+6] | ||
+ | mov byte[msg2+6], al | ||
+ | |||
+ | mov al, byte [msg1+7] | ||
+ | mov byte[msg2+7], al | ||
+ | |||
+ | mov al, byte [msg1+8] | ||
+ | mov byte[msg2+8], al | ||
+ | |||
+ | mov al, byte [msg1+9] | ||
+ | mov byte[msg2+9], al | ||
+ | |||
+ | mov al, byte [msg1+10] | ||
+ | mov byte[msg2+10], al | ||
+ | |||
+ | mov al, byte [msg1+11] | ||
+ | mov byte[msg2+11], al | ||
+ | |||
+ | mov al, byte [msg1+12] | ||
+ | mov byte[msg2+12], al | ||
+ | |||
+ | ;;; print new msg2 | ||
+ | mov eax, 4 | ||
+ | mov ebx, 1 | ||
+ | mov ecx, msg2 | ||
+ | mov edx, msg1Len | ||
+ | int 0x80 | ||
+ | |||
+ | ;;; exit | ||
+ | mov ebx, 0 | ||
+ | mov eax, 1 | ||
+ | int 0x80 | ||
+ | |||
+ | </source> | ||
<br /> | <br /> | ||
<br /> | <br /> |
Revision as of 08:14, 19 September 2012
--D. Thiebaut 09:08, 19 September 2012 (EDT)
A Program with 2 Strings
;;; movString1s.asm
;;; D. Thiebaut
;;;
;;;
;;;
;;; To assemble, link, and run:
;;; nasm -f elf -F stabs movString1s.asm
;;; ld -melf_i386 -o movStrings1 movStrings1.o
;;; ./movStrings1
;;;
section .data
msg1 db "Smith College", 10
msg1Len equ $-msg1
msg2 db ".............", 10
section .text
global _start
_start:
;;; print msg1
mov eax, 4
mov ebx, 1
mov ecx, msg1
mov edx, msg1Len
int 0x80
;;; print msg2
mov eax, 4
mov ebx, 1
mov ecx, msg2
mov edx, msg1Len
int 0x80
;;; exit
mov ebx, 0
mov eax, 1
int 0x80
Copying msg1 into msg2, 1 byte at a time
;;; movString1s.asm
;;; D. Thiebaut
;;;
;;; This version copies msg1 to msg2
;;;
;;; To assemble, link, and run:
;;; nasm -f elf -F stabs movString1s.asm
;;; ld -melf_i386 -o movStrings2 movStrings2.o
;;; ./movStrings2
;;;
section .data
msg1 db "Smith College", 10
msg1Len equ $-msg1
msg2 db ".............", 10
section .text
global _start
_start:
;;; print msg1
mov eax, 4
mov ebx, 1
mov ecx, msg1
mov edx, msg1Len
int 0x80
;;; print original msg2
mov eax, 4
mov ebx, 1
mov ecx, msg2
mov edx, msg1Len
int 0x80
;;; copy msg1 into msg2
mov al, byte [msg1]
mov byte[msg2], al
mov al, byte [msg1+1]
mov byte[msg2+1], al
mov al, byte [msg1+2]
mov byte[msg2+2], al
mov al, byte [msg1+3]
mov byte[msg2+3], al
mov al, byte [msg1+4]
mov byte[msg2+4], al
mov al, byte [msg1+5]
mov byte[msg2+5], al
mov al, byte [msg1+6]
mov byte[msg2+6], al
mov al, byte [msg1+7]
mov byte[msg2+7], al
mov al, byte [msg1+8]
mov byte[msg2+8], al
mov al, byte [msg1+9]
mov byte[msg2+9], al
mov al, byte [msg1+10]
mov byte[msg2+10], al
mov al, byte [msg1+11]
mov byte[msg2+11], al
mov al, byte [msg1+12]
mov byte[msg2+12], al
;;; print new msg2
mov eax, 4
mov ebx, 1
mov ecx, msg2
mov edx, msg1Len
int 0x80
;;; exit
mov ebx, 0
mov eax, 1
int 0x80