COLLEGE OF ARTS, SCIENCES AND TECHNOLOGY Experiment Number: Laboratory No. 1 Experiment Title: Name: Subject/ Section: Date Performed: Date Submitted: Instructor Name: Introduction to Assembly Language Programming Tools Marc Aeron T. Apolinar Computer Architecture and Organization Lab April 5, 2021 April 7, 2021 Mr. Julius Bancud I. II. III. IV. Presentation : Test Data: Analysis and Conclusion: Answer to Questions: Remarks: ____________________________________________________________________________________ __________________________________________________________________________________ Instructor Signature: _________________ LABORATORY NO. 1 Introduction to Assembly Language Programming Tools I. Objective To introduce the following assembly language programming tools: • DEBUG II. Components to be borrowed • PC power cords (2) • Keyboard (1) • Mouse (1) III. Conceptual Framework A. DEBUG is a program included in the MS-DOS and PC-DOS operating systems that allows the programmer to monitor program’s execution closely for debugging purposes. Specifically, it can be used to examine and alter the contents of memory to enter and run programs, and to stop programs at certain points in order to check or even change data. Figure 1 shows the DEBUG environment. Figure 1. DEBUG Environment Commands in DEBUG 1.1 Entering and exiting DEBUG • To enter the DEBUG program, simply type its name at the DOS level: A :\> DEBUG<return> After DEBUG and enter key (carriage return) have been entered, the DEBUG prompt “-“ will appear on the following line. DEBUG is now waiting for you to type in a command. • To exit Debug, simply type Q (quit command) after the DEBUG prompt: - Q <return> After the Q and enter key (carriage return) have been entered, DEBUG will return you to the DOS level. 1.2 Examining and altering the contents of registers • R, the REGISTER command. The register (R) command allows you to examine and/or alter the contents of the internal registers of the CPU. The R command has the following syntax: - R <register name> The R command will display all registers unless the optional <register name> field is entered, in this case only register named will be displayed and/or altered. 1.3 Coding and running programs in DEBUG. • A, the ASSEMBLE command. The assemble command is used to enter assembly language instructions into memory. - A <starting address> The starting address may be given as an offset number, in which case it is assumed to be an offset into the code segment, or the segment register can be specified explicitly. • U, the UNASSEMBLE command. The unassembled command displays the machine code in memory along with their equivalent assembly language instructions. The command can be given in either format shown below: - U <starting address> <ending address> - U <starting address> <L number of bytes> If the U command is entered with no addresses after it: “U <return>”, then DEBUG will display 32 bytes beginning at CS:IP. • • G, the GO command. The GO command instructs DEBUF to t the instructions found between the two given addresses. Its format is: - G <=starting address> <stop address(es)> If no addresses are given, DEBUG begins executing instructions at CS:IP until a breakpoint is reached. After a breakpoint is reached, DEBUG displays the register contents and returns you to the command prompt. Up to 10 stop addresses can be entered. DEBUG will stop execution at the first of these breakpoints that it reaches. • T, the TRACE command. The trace command allows you to trace through the execution programs one or more instructions at a time to verify the effect of the programs on registers and/or data. Its format is: - T <=starting address> <number of instructions> The trace command functions similarly to GO command in that if no starting address Is specified, it starts at CS:IP. 1.4 Data Manipulation in DEBUG • D, the DUMP command. The dump command is used to examine the contents of memory. The syntax of the D command is as follows: - D <start address> <end address> - D < start address> <L number of bytes> The D command can also be entered by itself, in which case debug will display 128 consecutive bytes beginning at DS:100. • F, the FILL command. The fill command is used to fill an area of memory with a data item. The syntax of the F command is as follows: - F <starting address> <ending address> <data> - F <starting address> <L number of bytes> <data> This command is useful in filling a block of memory with data, for example to initialize an area of memory with zeros. • E, the ENTER command. The enter command can be used to enter a list of data into a certain portion of memory. - E <address> <data list> - E <address> For example, - E 100 ‘John Smith’. This example showed how to enter ASCII data, which can be enclosed in either single or double quotes. 1.5 Loading and Writing programs • N, the NAME command. The name command initializes a filename in memory before using the load and write commands. Its format is : - N <drive name:> <filename> <extension name> After the code has been entered with the A command, CX must be set to contain the number of bytes to be saved and register BX must be set to 0. • W, the WRITE command. The write command is used to save instructions onto a disk. Its format is: -W • L, the LOAD command. The load command performs the opposite function of Write command. It loads from disk into memory starting at the specified address. Its syntax is: -L IV. Procedure DEBUG Environment 1. Types DEBUG at the command prompt of DOS then press ENTER key. 2. Command: R A. You will see a dash “-“ prompt that signifies DEBUG environment. Type R/r on this prompt then ENTER key. Illustrate the output: AX=0000 BX=0000 CX=0000 DX=0000 SP=FFFE BP=0000 SI=0000 DI=0000 DS=072A ES=072A SS=072A CS=072A IP=0100 NV UP EI NG NZ NA PO NC 072A:0100 C3 RET B. Type the following commands. Write the contents or observation on the space provided: REGISTER COMMAND CONTENTS/OBSERVATION IP - R IP IP 0100 CX - R CX CX 0000 AX - R AX AX 0000 DH - R DH It shows an error C. Write the appropriate command to modify the contents of the following registers. REGISTER COMMAND CONTENTS/OBSERVATION AX 0001 It shows an error but under the error there is 072A:0100. CX 0021 It shows an error IP 0100 It shows an error 3. Command: A Assemble the given program at the starting offset address 100h. Type A 100 then ENTER key. CS:0100 MOV AX, 1 MOV BX, 2 MOV CX, 3 ADD AX, BX ADD AX, CX INT 3 4. Command: U A. Write the command that will unassemble the program in number 3: Command: __________________________________________ B. What are the equivalent machine codes of the following instructions? INSTRUCTION MACHINE CODE MOV AX, 01 B90300 MOV CX, 3 01DB ADD AX, BX 0001 5. Command: G A. Execute the program in number 3. Type the given command Command: –g =0100 B. What are the contents of the following registers? AX BX CX 00006 0002 0003 6. Command: T A. Reset the values of AX, BX and CX and set value of IP to 0100. B. Execute program given in number 3 using trace command. C. Type T or t at the DEBUG prompt, then press ENTER key. Repeat this step until all instructions are executed. D. What are the contents of the following registers after executing each instruction? INSTRCUTION AX BX CX MOV AX, 1 0001 0000 0000 MOV BX, 2 0001 0002 0000 MOV CX, 3 0001 0002 0003 ADD AX, BX 0003 0002 0003 ADD AX,CX 0006 0002 0003 7. Command: D A. Illustrate or describe the output after executing the following D commands: COMMAND D 100 10F OUTPUT C3 01 00 BB 02 00 B9 03-00 01 D8 01 C8 00 00 00 D CX: 110 120 60 10 00 F0 60 10 00 F0-80 11 00 F0 60 10 00 F0 60 B. Type in the command: ___D_______ No. of bytes displayed: 128 Beginning Address: ___072A:0100___________ Ending Address: 072A:0170 8. Command: F A. Determine the contents of the following blocks of memory, after executing the commands. You may use the D command to display the contents: COMMAND BLOCK OF MEMORY DATA CONTENTS - F 100 10F FF 100 – 10F FF FF FF FF FF FF FF FF-FF FF FF FF FF FF FF FF - F 100 L20 00 FF 100 – 11F 00 FF 00 FF 00 FF-00 FF 00 FF 00 FF 00 FF 00 FF B. Fill the following blocks of memory with the specified data. Write the appropriate command. BLOCK MEMORY OF DATA COMMAND 100 - 110 00 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 00 11F - 130 00, 01, 10, 11 00 (ALTERNATELY) 01 10 11 00 01 10 11 00-01 10 11 00 01 10 11 00 01 9. Command: E A. Enter the data ‘John Snith’ at starting address 100h: What is the command? -E 0100 ‘John Snith’ B. Modify the data ‘John Snith’ to ‘John Smith’ (ASCII code of m=6D) What is the command? -E 106 6D ______________________________________ V. PROBLEM SOLVING 1) Trace the given code below using DEBUG. Write the contents of AX and flag registers on the space provided. Verify the result by computing it manually. INSTRCUTION AX FLAG REGISTER MOV AX, 1234H 1234 NU UP EI NG NZ NA PO NC ADD AX, 5678H 68AC NU UP EI PL NZ NA PE NC ADC AX, 9BCH 7268 NV UP EI PL NZ AC PO NC INT 3 7268 NV UP EI PL NZ AC PO NC 2) Assume that the program listed below is to be stored in the memory starting at address CS:0500. Assemble the program below. MOV AX, 0500 MOV DS, AX MOV SI, 0100 MOV DI, 0120 MOV CX, 0020 MOV AL, [SI] MOV [DI], AL INC SI INC DI DEC CX JNZ 050E NOP Execute the program and trace each program and observe the contents of the registers and the memory locations used. Conclusion: I conclude that debug helps you to change and monitor your programs execution by using different kinds of debug. Aside from that Debug allows you to examine and alter memory. Then by doing this experiment you can manipulate your registers, like ax and bx etc. Debug uses hexadecimal for you to execute your program. Furthermore, by displaying your addresses, I conclude that by typing the command, the address offset will show, the content and the left corner will show your ascii code.