CSC231 Homework Solutions 2017

From dftwiki3
Revision as of 16:58, 22 April 2017 by Thiebaut (talk | contribs)
Jump to: navigation, search

--D. Thiebaut (talk) 17:57, 22 April 2017 (EDT)


Problem 1

;;; mystery.asm 
;;; D. Thiebaut  
;;;                
;;; To assemble, link, and run:  
;;;     nasm -f elf  mystery.asm  
;;;     ld -melf_i386 -o mystery mystery.o 
;;;     ./mystery        
;;;      

                section .data
Hello           db      "Hello there!", 10, 10
HelloLen        equ     $-Hello
	
                section .text
                global  _start
_start:

;;; print Hello and a space after it
	
                mov     eax, 4          ; write    
                mov     ebx, 1          ; stdout  
                mov     ecx, Hello      ; address of message to print    
                mov     edx, 6          ; print only 6 chars
                int     0x80

;;; print ! and two line feed chars

                mov     eax, 4          ; write    
                mov     ebx, 1          ; stdout  
                mov     ecx, Hello+11   ; address of ! char
                mov     edx, 3          ; print only 3 chars
                int     0x80

;;; exit                                                                                                                                    
                mov     ebx, 0
                mov     eax, 1
                int     0x80


hw1.asm


;;; hw1.asm
;;; D. Thiebaut  
;;;                
;;; To assemble, link, and run:  
;;;     nasm -f elf  hw1.asm  
;;;     ld -melf_i386 -o hw1 hw1.o 
;;;     ./hw1        
;;;      

                section .data
msg             db      "  CSC231 Assembly "
linefeed	db	10
dashline        db	"------------------"
lineLen		equ	$-dashline
	
                section .text
                global  _start
_start:

;;; print message                                                                                                                           
                mov     eax, 4          ; write    
                mov     ebx, 1          ; stdout  
                mov     ecx, dashline   ; address of message to print    
                mov     edx, lineLen   	; # of chars to print  
                int     0x80

                mov     eax, 4          ; write    
                mov     ebx, 1          ; stdout  
                mov     ecx, dashline   ; address of message to print    
                mov     edx, lineLen   	; # of chars to print  
                int     0x80

		mov	eax, 4		;print line-feed
		mov	ebx, 1
		mov	ecx, linefeed
		mov	edx, 1
		int	0x80

                mov     eax, 4		; write ----
		mov     ebx, 1 		; stdout
		mov     ecx, dashline 	; address of message to print
		mov     edx, 9  	; # of chars to print
		int     0x80

                mov     eax, 4          ; write message
                mov     ebx, 1          ; stdout  
                mov     ecx, msg 	; address of message to print    
                mov     edx, lineLen    ; # of chars to print  
                int     0x80
	
                mov     eax, 4		; write ----
		mov     ebx, 1 		; stdout
		mov     ecx, dashline 	; address of message to print
		mov     edx, 9  	; # of chars to print
		int     0x80

		mov	eax, 4		;print line-feed
		mov	ebx, 1
		mov	ecx, linefeed
		mov	edx, 1
		int	0x80

                mov     eax, 4          ; write    
                mov     ebx, 1          ; stdout  
                mov     ecx, dashline   ; address of message to print    
                mov     edx, lineLen   	; # of chars to print  
                int     0x80

                mov     eax, 4          ; write    
                mov     ebx, 1          ; stdout  
                mov     ecx, dashline   ; address of message to print    
                mov     edx, lineLen   	; # of chars to print  
                int     0x80

		mov	eax, 4		;print line-feed
		mov	ebx, 1
		mov	ecx, linefeed
		mov	edx, 1
		int	0x80

;;; exit                                                                                                                                    
                mov     ebx, 0
                mov     eax, 1
                int     0x80