CSC231 Copying Strings in RAM

From dftwiki3
Revision as of 08:14, 19 September 2012 by Thiebaut (talk | contribs) (A Program with 2 Strings)
Jump to: navigation, search

--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