Homework 2
Data/Debugger Use/Push/Pop/Mov/Xchg

Document last modified: 
Overview Understanding how different data types are defined appropriate operations is critical to developing correct software systems. Two's complement and unsigned representations are commonly used for numeric representations while ASCII is the most common representation for characters. To understand the operation of the machine it is first necessary to understand the theory and practice on which that operation is based, exercises will provide practice in numeric representations and operations.

Program development using assembly language demands the use of a run-time debugger that allows step-by-step program execution. DEBUG is described in the text and is simple, supporting only absolute memory addresses (a numerical address versus a symbolic label). 


Homework Assignment and Turn In The homework consists of executing two programs (given below) and recording the effects of the execution. Follow the section Steps Using DEBUG below and turn in worksheets for Homework Assignment 1 and Assignment 2. Each should be completed by hand and then verified using DEBUG.

Steps Using DEBUG

1.   Copy program below to file named PR_2_1.ASM, it should be possible to copy and paste.
 
Assignment 1 program - PR_2_1.ASM
           PAGE    80,132
;
; D A T A   S E G M E N T   D E F I N I T I O N
;
DATA    SEGMENT
        TEMP       DW      0000110011010101B
DATA    ENDS
;
; C O D E   S E G M E N T   D E F I N I T I O N
;
CODE       SEGMENT
           ASSUME  CS:CODE, DS:DATA, SS:SSeg

PR_2_1     PROC    FAR
           MOV     AX,SEG DATA
           MOV     DS,AX

           MOV     AX,0123H
           MOV     BX,4567H
           MOV     CX,89ABH
           MOV     DX,0CDEFH
;*** CHECKPOINT A ***
           PUSH    AX
           PUSH    BX
           PUSH    CX
           PUSH    DX
;*** CHECKPOINT B ***
           POP     AX
           POP     BX
           PUSH    AX
           PUSH    BX
;*** CHECKPOINT C ***
           POP     DX
           POP     CX
           POP     BX
           POP     AX
;*** CHECKPOINT D ***
           MOV     AH,4CH              ;RETURN TO DOS
           INT     21H
PR_2_1     ENDP

CODE       ENDS
;
; S T A C K   S E G M E N T   D E F I N I T I O N
;
SSeg      Segment        STACK       ;;Stack segment of 254 bytes
          DB             254 dup(?)
SSeg      Ends           
          END     PR_2_1
.

2.   Open a Command prompt. Change the default drive to the location of PR_2_1.ASM, assemble, link and start the DEBUG debugger using the following commands.

3.   The debugger will display the '-' prompt, enter: to execute the first two instructions:
MOV     AX,SEG DATA
MOV     DS,AX
4.    Continue entering p to follow the remainder of the program execution and witness the effect upon the CPU registers.

5.   For Assignment 1, list the values of the registers and stack at checkpoints A through D of the program listing. To determine these values execute the program to the instruction following the CHECKPOINT comment. For Checkpoint B in the above program, the debugger should show the following:

AX=0123 BX=4567 CX=89AB DX=CDEF SP=00F8 BP=0000 SI=0000 DI=0000
DS=12BF ES=12AF SS=12C3 CS=12C0 IP=0014 NV UP EI PL NZ NA PO NC
12C0:0014 52 PUSH DX
-p

AX=0123 BX=4567 CX=89AB DX=CDEF SP=00F6 BP=0000 SI=0000 DI=0000
DS=12BF ES=12AF SS=12C3 CS=12C0 IP=0015 NV UP EI PL NZ NA PO NC
12C0:0015 58 POP AX

6.   The exercise also requests that the stack values be listed at each checkpoint. Use the dump memory command to examine the memory that holds the stack. The following examines memory after the Push Dx is executed placing CDEF on the stack. the command d ss:f0 dumps the stack segment starting at offset f0. The interpretation of the dump is that ss:00F6-00F7 is the stack location holding the value CDEF. Recall that a word value is stored in memory backward in low:high byte order so CDEF  is actually stored as EF CD in address 00F6 and 00F7 respectively. 

-d ss:f0
12C3:00F0 15 00 C0 12 00 0C EF CD-AB 89 67 45 23 01 DA A2

7.   Repeat the steps of executing to each checkpoint using p key.

8.   Don't forget Assignment 2. The program to be used is PR_2_2.ASM given below.
 

Assignment 2 program - PR_2_2.ASM
           PAGE    80,132
;
; D A T A   S E G M E N T   D E F I N I T I O N
;
DATA    SEGMENT
        ALPHA      DB      35
        BETA       DW      01ABH
        GAMMA      DW      45EFH
        LAMBDA     DB      CONSTANT
        OMEGA      DW      67CDH
DATA    ENDS

CONSTANT   EQU     10001001B

;
;===============================================================
;
; C O D E   S E G M E N T   D E F I N I T I O N
;
     
CODE       SEGMENT
           ASSUME  CS:CODE, DS:DATA, SS: SSeg

PR_2_2     PROC    FAR
           MOV     AX,SEG DATA         ;SET DS-REGISTER TO POINT
           MOV     DS,AX               ;TO DATA SEGMENT

;*** CHECKPOINT A ***
           MOV     AH,CONSTANT
           MOV     AL,ALPHA
           MOV     BX,GAMMA
           XCHG    AH,BH
           XCHG    AX,BETA
           MOV     ALPHA,AH
           MOV     LAMBDA,AL
;*** CHECKPOINT B ***
           MOV     CX,OMEGA
           XCHG    BL,CH
           MOV     GAMMA,BX
           MOV     OMEGA,CX
;*** CHECKPOINT C ***
           MOV     AH,4CH              ;RETURN TO DOS

           INT     21H
PR_2_2     ENDP

CODE       ENDS
;
; S T A C K   S E G M E N T   D E F I N I T I O N
;
SSeg      Segment     STACK       ;;Stack segment of 254 bytes
            DB        254 dup(?)
SSeg      Ends
          END     PR_2_2

9.    For Assignment 2 it will be useful to view the CPU registers and data segment memory to observe the variable value at each checkpoint.