CS323 - Note 2 – Day 2 – 1/25/2006
First & Second Programs

Number Systems (review) See Handout for today.

        Decimal, binary, hexadecimal, octal
        Signed Integers 
               Signed magnitude
               One’s complement
               Two’s complement

Unix – demo if necessary: PuTTy and WinSCP

Steps in Assembly Programming - demo if necessary. (edit, assemble, link, run) – mp00

To edit, use : joe first.asm   (or vi or emacs or WinSCP editor)

 

To assemble your program, give the following command:

 

            nasm –f elf first.asm

 

      If this command works correctly, you will simply get a new prompt and a file first.o will be created.  Use the ls command to see that the file was created.  Note ELF stands for Executable and Linkable Format.

 

To create an executable program, give the following command:

 

            gcc first.o driver.c asm_io.o

 

      If this command works correctly, you will simply get a new prompt and a file a.out will be created.

 

To run the program, give the command:

 

            a.out

 

Look at an list file (use –l listing_file)

See page 21 in Carter for a detailed discussion of first.asm

Debugging

To debug use the commands(macros) given in Carter’s textbook:

      dump_regs to dump/display the registers

      dump_mem to dump/display sections of memory

      dump_stack to dump/display the stack

Skeleton program

;
; file: skel.asm
; This file is a skeleton that can be used to start assembly programs.

%include "asm_io.inc"
segment .data
;
; initialized data is put in the data segment here
;


segment .bss
;
; uninitialized data is put in the bss segment
; block-started-by-symbol
 

segment .text
        global  asm_main
asm_main:
        enter   0,0               ; setup routine
        pusha

;
; code is put in the text segment. Do not modify the code before
; or after this comment.
;


        popa
        mov     eax, 0            ; return back to C
        leave                    
        ret

Basic Concepts

        Assembly is NOT totally case insensitive, e.g. 
               Register names like EAX and eax are the same.
               Variable names like prompt and PROMPT are different.
 
        Assembly Program has three segments
               Stack, data, and code
 
        Pseudo Operations /Directives
            -directs assembler to do something, e.g.
               -- define constants
               -- define memory
               -- group memory into segments
               -- include files (possibly conditionally)
 
        Directives are not machine instructions
        
        %define   BUFSIZE   10
 
        Pseudo operations DB, DW, DD, DQ, DT  (see page 14 of Carter)
        Define variables with initial values
        Use resb, resw, resd, resq, rest to reserve values with NO initial values.
 
        Data types: byte, word, double word, quad word, ten bytes
        See page 14 and 15 in Carter text
 
        Registers – 16 bit 
           AX, BX, CX, DX, DS  
           Each one is a word, and has a high byte and a low byte
           AX:  AH  AL
        Registers – 32 bit : eax, ebx, ecx, edx, edi, esi
           AX is the lower half of EAX, AL is lower half of AX, AH is upper half of AX
           Same can be said for relationship between bx and ebx, cx and ecx, dx and edx

Examine mp10 – second assembler program

Nasm Documentation & Programming GroundRules

 
See S:\Academic\CSSE\CS\Cs323\Nasm\SampleNASM\nasmdoc.pdf
 
Programming Groundrules (http://www.uwplatt.edu/csse/Courses/CS323/asm-rules.html)