CSC231 Mini Lab 1 Solution and Discussion

From dftwiki3
Revision as of 08:47, 12 September 2012 by Thiebaut (talk | contribs)
Jump to: navigation, search

--D. Thiebaut 09:38, 12 September 2012 (EDT)


Solution 1


;;; minilab1_v1.asm
;;; D. Thiebaut
;;; prints this string on the screen:
;;;
;;; 	*********************************
;;;     * Welcome to CSC231             *
;;;     * Home of the Assembly Language *
;;;     *********************************


	section	.data

msg	db	"*********************************", 10
	db	"* Welcome to CSC231             *", 10
	db	"* Home of the Assembly Language *", 10	
	db	"*********************************", 10, 10
	
msgLen	equ	$-msg

	section	.text
	global	_start
_start:
	mov	eax,4
	mov	ebx,1
	mov	ecx,msg
	mov	edx,msgLen
	int	0x80

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


Solution 2


;;; minilab1_v2.asm
;;; D. Thiebaut
;;; prints this string on the screen:
;;;
;;; 	*********************************
;;;     * Welcome to CSC231             *
;;;     * Home of the Assembly Language *
;;;     *********************************


	section	.data

msg	db	"*********************************", 10
msgLen1	equ	$-msg	
	db	"* Welcome to CSC231             *", 10
	db	"* Home of the Assembly Language *", 10	
msgLen2	equ	$-msg
	
	section	.text
	global	_start
_start:
	
;;; print first 3 lines
	mov	eax,4
	mov	ebx,1
	mov	ecx,msg
	mov	edx,msgLen2
	int	0x80

;;; print first line back, to close box
	mov	eax,4
	mov	ebx,1
	mov	ecx,msg
	mov	edx,msgLen1
	int	0x80

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



What is the trade-off?

  • Generate the listing of the assembly:
      nasm -f elf -F stabs -l minilab1_v1.lst  minilab1_v1.asm            (that's a minus ell option in the command)
    
      ls -l minilab1_v1.*

  • Look at the list
      -rwx------. 1 231a 231a 1079 Sep 12 09:18 minilab1_v1*
      -rw-------. 1 231a 231a  606 Sep 12 09:18 minilab1_v1.asm
      -rw-------. 1 231a 231a 2398 Sep 12 09:47 minilab1_v1.lst
      -rw-------. 1 231a 231a 1168 Sep 12 09:47 minilab1_v1.o 
  • Look at the listing generated


     1                                  ;;; minilab1.asm
     2                                  ;;; D. Thiebaut
     3                                  ;;; prints this string on the screen:
     4                                  ;;;
     5                                  ;;; 	*********************************
     6                                  ;;;     * Welcome to CSC231             *
     7                                  ;;;     * Home of the Assembly Language *
     8                                  ;;;     *********************************
     9                                  
    10                                  
    11                                  	section	.data
    12                                  
    13 00000000 2A2A2A2A2A2A2A2A2A-     msg	db	"*********************************", 10
    14 00000009 2A2A2A2A2A2A2A2A2A-
    15 00000012 2A2A2A2A2A2A2A2A2A-
    16 0000001B 2A2A2A2A2A2A0A     
    17 00000022 2A2057656C636F6D65-     	db	"* Welcome to CSC231             *", 10
    18 0000002B 20746F204353433233-
    19 00000034 312020202020202020-
    20 0000003D 20202020202A0A     
    21 00000044 2A20486F6D65206F66-     	db	"* Home of the Assembly Language *", 10	
    22 0000004D 207468652041737365-
    23 00000056 6D626C79204C616E67-
    24 0000005F 75616765202A0A     
    25 00000066 2A2A2A2A2A2A2A2A2A-     	db	"*********************************", 10, 10
    26 0000006F 2A2A2A2A2A2A2A2A2A-
    27 00000078 2A2A2A2A2A2A2A2A2A-
    28 00000081 2A2A2A2A2A2A0A0A   
    29                                  	
    30                                  msgLen	equ	$-msg
    31                                  
    32                                  	section	.text
    33                                  	global	_start
    34                                  _start:
    35 00000000 B804000000              	mov	eax,4
    36 00000005 BB01000000              	mov	ebx,1
    37 0000000A B9[00000000]            	mov	ecx,msg
    38 0000000F BA89000000              	mov	edx,msgLen
    39 00000014 CD80                    	int	0x80
    40                                  
    41                                  ;;; exit
    42 00000016 B801000000              	mov	eax,1
    43 0000001B BB00000000              	mov	ebx,0
    44 00000020 CD80                    	int	0x80
    45                                  
    46