Programming with Assembly Language

CS 272
Sam Houston State Univ.
Dr. Tim McGuire

Learning Assembly Language

Advantages of Assembly Language Disadvantages of assembly language Structure of an assembly language program The Header %TITLE "Sample Header"
MODEL small
Equates Count EQU 10
Element EQU 5
Size = Count * Element
MyString EQU "Maze of twisty passages"
Size = 0
The Data Segment Reserving space for variables DATASEG
numRows    DB   25
numColumns DB   80
videoBase  DW   0800h
aTOm DB "ABCDEFGHIJKLM" The Program Body An example Label   Mnemonic Operand     Comment
exCode  DB      0             ;A byte variable
myWord  DW      ?             ;Uninitialized word var.
Start:  mov     ax,@data      ;Initialize DS to address
        mov     ds, ax        ; of data segment
        jmp     Exit          ;Jump to Exit label
        mov     cx, 10        ;This line skipped!
Exit:   mov     ah, 04Ch      ;DOS function: Exit prog
        mov     al, [exCode]  ;Return exit code value
        int     21h           ;Call DOS. Terminate prog
        END     Start         ;End program and specify
                              ; entry point
The Label Field Legal and Illegal Labels The Mnemonic Field The Operand Field NOP         ;no operands -- does nothing
INC AX      ;one operand -- adds 1 to the contents of AX
ADD WORD1,2 ;two operands -- adds 2 to the contents
            ; of memory word WORD1
The Comment Field Good and Bad Comments MOV CX,0 ;move 0 to CX MOV CX,0 ;CX counts terms, initially 0 ;
; Initialize registers
The Closing END Start ;End of program / entry point Assembling a Program edit myprog.asm tasm myprog produces myprog.obj tlink myprog produces myprog.exe Dealing with Errors Using the Debugger tasm /zi myprog
tlink /v myprog
td myprog
.COM and .EXE files Ending a Program