Microsoft PowerPoint - C15_LECTURE_NOTE_04.ppt

Similar documents
Microsoft PowerPoint - C15_LECTURE_NOTE_04.ppt

untitled

Microsoft PowerPoint - C15_LECTURE_NOTE_05.ppt

Microsoft PowerPoint - C15_LECTURE_NOTE_05.ppt

Microsoft PowerPoint - C15_LECTURE_NOTE_06

(Load Project) (Save Project) (OffLine Mode) (Help) Intel Hex Motor

Microsoft PowerPoint - C15_LECTURE_NOTE_06

,768 32,767 32K JMP Jnnn (386+) LOOP CALL [Label:] JMP short/near/far address L10: jmp jmp L20: L10 L20

Windows XP

幻灯片 1

Microsoft Word - template.doc

PowerPoint Presentation

1.ai

Microsoft PowerPoint - os_4.ppt

穨control.PDF

untitled

els0xu_zh_nf_v8.book Page Wednesday, June, 009 9:5 AM ELS-0/0C.8

Microsoft PowerPoint - CA_02 Chapter5 Part-I_Single _V2.ppt

Microsoft PowerPoint - C15_LECTURE_NOTE_11

Bus Hound 5

K7VT2_QIG_v3

Improved Preimage Attacks on AES-like Hash Functions: Applications to Whirlpool and Grøstl

Chn 116 Neh.d.01.nis

2/80 2

Guide to Install SATA Hard Disks

Important Notice SUNPLUS TECHNOLOGY CO. reserves the right to change this documentation without prior notice. Information provided by SUNPLUS TECHNOLO

第 15 章 程 式 編 写 語 言 15.1 程 式 編 写 語 言 的 角 色 程 式 編 寫 語 言 是 程 式 編 寫 員 與 電 腦 溝 通 的 界 面 語 法 是 一 組 規 則 讓 程 式 編 寫 員 將 字 詞 集 合 起 來 電 腦 是 處 理 位 元 和 字 節 的 機 器, 與

EK-STM32F

Microsoft PowerPoint - Lecture7II.ppt

Microsoft PowerPoint - STU_EC_Ch08.ppt

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

TX-NR3030_BAS_Cs_ indd

<4D F736F F F696E74202D20B5DAD2BBD5C228B4F2D3A1B0E6292E BBCE6C8DDC4A3CABD5D>

AL-M200 Series

入學考試網上報名指南

Microsoft Word - HC20138_2010.doc

IP505SM_manual_cn.doc

Microsoft PowerPoint - STU_EC_Ch04.ppt

CC213

1 CPU

<4D F736F F D20C7B6C8EBCABDCFB5CDB3C9E8BCC6CAA6B0B8C0FDB5BCD1A75FD1F9D5C22E646F63>

AN INTRODUCTION TO PHYSICAL COMPUTING USING ARDUINO, GRASSHOPPER, AND FIREFLY (CHINESE EDITION ) INTERACTIVE PROTOTYPING

(Guangzhou) AIT Co, Ltd V 110V [ ]! 2

epub83-1

2015 Chinese FL Written examination

Ác Åé å Serial ATA ( Sil3132) S A T A (1) SATA (2) BIOS SATA (3)* RAID BIOS RAID (4) SATA (5) SATA (a) S A T A ( S A T A R A I D ) (b) (c) Windows XP

HCD0174_2008

CANVIO_AEROCAST_CS_EN.indd

目 录

Gerotor Motors Series Dimensions A,B C T L L G1/2 M G1/ A 4 C H4 E

User ID 150 Password - User ID 150 Password Mon- Cam-- Invalid Terminal Mode No User Terminal Mode No User Mon- Cam-- 2

Microsoft Word - HSK使用手册.doc

Panaboard Overlayer help

untitled

LSC操作说明

DR2010.doc

Chapter 2

2 2 3 DLight CPU I/O DLight Oracle Solaris (DTrace) C/C++ Solaris DLight DTrace DLight DLight DLight C C++ Fortran CPU I/O DLight AM

EC51/52 GSM /GPRS MODEN

WinMDI 28

Microsoft Word - ChineseSATII .doc

Microsoft Word - CX VMCO 3 easy step v1.doc

ch_code_infoaccess

KillTest 质量更高 服务更好 学习资料 半年免费更新服务

Tel:

Cadence SPB 15.2 VOICE Cadence SPB 15.2 PC Cadence 3 (1) CD1 1of 2 (2) CD2 2of 2 (3) CD3 Concept HDL 1of 1

lan03_yen

Some experiences in working with Madagascar: installa7on & development Tengfei Wang, Peng Zou Tongji university

Gerolor Motors Series Dimensions A,B C T L L G1/2 M8 G1/ A 4 C H4 E

untitled

Untitled-3

快乐蜂(Jollibee)快餐连锁店 的国际扩张历程

ARM JTAG实时仿真器安装使用指南

KDC-U5049 KDC-U4049 Made for ipod, and Made for iphone mean that an electronic accessory has been designed to connect specifically to ipod, or iphone,

Preface This guide is intended to standardize the use of the WeChat brand and ensure the brand's integrity and consistency. The guide applies to all d

IP TCP/IP PC OS µclinux MPEG4 Blackfin DSP MPEG4 IP UDP Winsock I/O DirectShow Filter DirectShow MPEG4 µclinux TCP/IP IP COM, DirectShow I

Microsoft PowerPoint - Eisenstein_ABET_Presentation_Beijing_Oct_2007-Chinese.ppt [兼容模式]

從篤加有二「區」談當代平埔文化復振現相

投影片 1

SuperMap 系列产品介绍

Logitech Wireless Combo MK45 English

Oracle 4

ICD ICD ICD ICD ICD

IP Access Lists IP Access Lists IP Access Lists

VASP应用运行优化

C++ 程式設計

MATLAB 1

Microsoft Word - 先玉335 copy.doc

Edge-Triggered Rising Edge-Triggered ( Falling Edge-Triggered ( Unit 11 Latches and Flip-Flops 3 Timing for D Flip-Flop (Falling-Edge Trigger) Unit 11

Microsoft Word RCE MP_Year Book.doc

科学计算的语言-FORTRAN95

國 立 政 治 大 學 教 育 學 系 2016 新 生 入 學 手 冊 目 錄 表 11 國 立 政 治 大 學 教 育 學 系 博 士 班 資 格 考 試 抵 免 申 請 表 論 文 題 目 申 報 暨 指 導 教 授 表 12 國 立 政 治 大 學 碩 博 士 班 論

國家圖書館典藏電子全文

3 (s05q6) The diagram shows the velocity-time graph for a lift moving between floors in a building. The graph consists of straight line segments. In t

TI 3 TI TABLE 4 RANDBIN Research of Modern Basic Education

ebook140-9

Chapter 9: Objects and Classes

1505.indd

Transcription:

MACHINE LANGUAGE CODING AND THE DEBUG SOFTWARE DEVELOPMENT PROGRAM OF THE PC MACHINE LANGUAGE CODING AND THE DEBUG SOFTWARE DEVELOPMENT PROGRAM OF THE PC 4.1 Converting Assembly Language Instructions to Machine Code 4.2 Encoding a Complete Program in Machine Code 4.3 The PC and Its DEBUG Program 4.4 Examining and Modifying the Contents of Memory 4.5 Input and Output of Data 611 37100 微處理機原理與應用 Lecture 04-2 1

THE DEBUG, A SOFTWARE DEVELOPMENT PROGRAM FOR THE PC 4.6 Hexadecimal Addition and Subtraction 4.7 Loading, Verifying and Saving Machine Language Program 4.8 Assembling Instructions with the Assemble Command 4.9 Executing Instructions and Programs with the TRACE and GO command 4.10 Debugging a Program 611 37100 微處理機原理與應用 Lecture 04-3 4.1 Converting Assembly Language Instructions to Machine Code General instruction format for machine code 611 37100 微處理機原理與應用 Lecture 04-4 2

4.1 Converting Assembly Language Instructions to Machine Code Byte 1 specification Opcode field (6-bits) Specifies the operation to be performed Register direction bit (D-bit) 1 the register operand is a destination operand 0 the register operand is a source operand Data size bit (W-bit) 1 16-bit data size 0 8-bit data size 611 37100 微處理機原理與應用 Lecture 04-5 4.1 Converting Assembly Language Instructions to Machine Code Byte 2 specification Mode (MOD) field (2-bits) Together with R/M field to specify the second operand Register (REG) field (3-bit) Identifies the register for the first operand Register/Memory (R/M) field (3-bit) Register (REG) field encoding 611 37100 微處理機原理與應用 Lecture 04-6 3

4.1 Converting Assembly Language Instructions to Machine Code Byte 2 specification MOD field and R/M field encoding 611 37100 微處理機原理與應用 Lecture 04-7 4.1 Converting Assembly Language Instructions to Machine Code MOV BL, AL Encode the above instruction in machine code OPCODE = 100010 (for MOV), D = 0 (source), W = 0 (8-bit) This leads to BYTE 1 = 10001000 2 = 88 16 In byte 2 the source operand, specified by REG, is AL REG = 000, MOD = 11, R/M = 011 Therefore, BYTE 2 = 11000011 2 = C3 16 MOV BL, AL = 88C3 16 611 37100 微處理機原理與應用 Lecture 04-8 4

4.1 Converting Assembly Language Instructions to Machine Code ADD AX, [SI] Encode the above instruction in machine code OPCODE = 000000 (for ADD), D = 1 (dest.), W = 1 (16-bit) This leads to BYTE 1 = 00000011 2 = 03 16 In byte 2 the destination operand, specified by REG, is AX REG = 000, MOD = 00, R/M = 100 Therefore, BYTE 2 = 00000100 2 = 04 16 ADD AX, [SI] = 0304 16 611 37100 微處理機原理與應用 Lecture 04-9 4.1 Converting Assembly Language Instructions to Machine Code XOR CL, [1234H] Encode the above instruction in machine code OPCODE = 001100 (for XOR), D = 1 (dest.), W = 0 (8-bit) This leads to BYTE 1 = 00110010 2 = 32 16 In byte 2 the destination operand, specified by REG, is CL REG = 001, MOD = 00, R/M = 110 Therefore, BYTE 2 = 00001110 2 = 0E 16 BYTE 3 = 34 16 BYTE 4 = 12 16 XOR CL, [1234H] = 320E3412 16 611 37100 微處理機原理與應用 Lecture 04-10 5

4.1 Converting Assembly Language Instructions to Machine Code ADD [BX][DI]+1234H, AX Encode the above instruction in machine code OPCODE = 000000 (for ADD), D = 0 (source), W = 1 (16-bit) This leads to BYTE 1 = 00000001 2 = 01 16 In byte 2 the destination operand, specified by REG, is AX REG = 000, MOD = 10, R/M = 001 Therefore, BYTE 2 = 10000001 2 = 81 16 BYTE 3 = 34 16 BYTE 4 = 12 16 ADD [BX][DI]+1234H, AX = 01813412 16 611 37100 微處理機原理與應用 Lecture 04-11 4.1 Converting Assembly Language Instructions to Machine Code Additional one-bit field and their functions Field S V Z Value 0 1 0 1 0 1 Function No sign extension Sign extend 8-bit immediate data to 16 bits if W=1 Shift/rotate count is one Shift/rotate count is specified in CL register Repeat/loop while zero flag is clear Repeat/loop while zero flag is set Instructions that involve a segment register (SR-field) Register ES CS SS DS 611 37100 微處理機原理與應用 Lecture 04-12 SR 00 01 10 11 6

4.1 Converting Assembly Language Instructions to Machine Code MOV WORD PTR [BP][DI]+1234H, 0ABCDH Encode the above instruction in machine code This example does not follow the general format From Fig. 3-1 MOV -> 1100011W, and W = 1 for word-size data BYTE 1 = 11000111 2 = C7 16 BYTE 2 = (MOD)000(R/M) = 10000011 2 = 83 16 BYTE 3 = 34 16 BYTE 4 = 12 16 BYTE 5 = CD 16 BYTE 6 = AB 16 MOV WORD PTR [BP][DI]+1234H, 0ABCDH = C7833412CDAB 16 611 37100 微處理機原理與應用 Lecture 04-13 4.1 Converting Assembly Language Instructions to Machine Code MOV [BP][DI]+1234H, DS Encode the above instruction in machine code This example does not follow the general format From Fig. 3-6 MOV -> 10001100, and the instruction is 10001100(MOD)0(SR)(R/M)(DISP) From Fig. 4-5 we find that for DS, the SR = 11 Therefore, the instruction is coded as MOV [BP][DI]+1234H, DS =10001100100110110011010000010010 2 =8C9B3412 16 611 37100 微處理機原理與應用 Lecture 04-14 7

4.2 Encoding a Complete Program in Machine Code Steps in encoding a complete assembly program: Identify the general machine code format (Fig. 3-6) Evaluate the bit fields (Fig. 4-2,4-3,4-4,4-5) Express the binary-code instruction in hexadecimal form To execute the program, the machine code of the program must be stored in the code segment of memory. The first byte of the program is stored at the lowest address. 611 37100 微處理機原理與應用 Lecture 04-15 4.2 Encoding a Complete Program in Machine Code Encode the block move program in Fig. 4-6(a) and show how it would be stored in memory starting at address 200 16. MOV AX, 2000H MOV DS, AX MOV SI, 100H MOV DI, 120H MOV CX, 10H NXTPT: MOV AH, [SI] MOV [DI], AH INC SI INC DI DEC CX JNZ NXTPT NOP ;LOAD AX REGISTER ;LOAD DATA SEGMENT ADDRESS ;LOAD SOURCE BLOCK POINTER ;LOAD DESTINATION BLOCK POINTER ;LOAD REPEAT COUNTER ;MOVE SOURCE BLOCK ELEMENT TO AH ;MOVE ELEMENT FROM AH TO DEST. BLOCK ;INCREMENT SOURCE BLOCK POINTER ;INCREMENT DESTINATION BLOCK POINTER ;DECREMENT REPEAT COUNTER ;JUMP TO NXTPT IF CX NOT EQUAL TO ZERO ;NO OPERATION 611 37100 微處理機原理與應用 Lecture 04-16 8

4.2 Encoding a Complete Program in Machine Code 611 37100 微處理機原理與應用 Lecture 04-17 4.2 Encoding a Complete Program in Machine Code 611 37100 微處理機原理與應用 Lecture 04-18 9

4.3 The PC and Its DEBUG Program Using DEBUG, the programmer can issue commands to the microcomputer. Loading the DEBUG program C:\DEBUG Six kinds of information are entered as part of a command: A command letter An address A register name A file name A drive name Data 611 37100 微處理機原理與應用 Lecture 04-19 4.3 The PC and Its DEBUG Program The DEBUG program command set 611 37100 微處理機原理與應用 Lecture 04-20 10

4.3 The PC and Its DEBUG Program An initial state when with the loading of DEBUG 0100 IP 00000 16 Memory 1342 CS 1342 DS 1342 SS 1342 ES 0000 AX 0000 BX 0000 CX 0000 DX 13420 16 Active code segment, data segment, stack segment, and extra segment (64 K bytes) FFEE SP 0000 BP 0000 SI 0000 DI 0040 Flags FFFFF 8088/8086 MPU 16 611 37100 微處理機原理與應用 Lecture 04-21 4.3 The PC and Its DEBUG Program Syntax for the REGISTER (R) command R [REGISTER NAME] e.g. -R AX ( ) AX 0000 :_ :00FF ( ) _ ;This alter the content of AX 611 37100 微處理機原理與應用 Lecture 04-22 11

4.3 The PC and Its DEBUG Program Verify the initialized state of the 8088 by examining the contents of its registers with the Register command -R ( ) 611 37100 微處理機原理與應用 Lecture 04-23 4.3 The PC and Its DEBUG Program Register mnemonics for the R command Symbol AX BX CX DX SI DI SP BP CS DS SS ES F IP Register Accumulator register Base register Count register Data register Source index register Destination index register Stack pointer register Base pointer register Code segment register Data segment register Stack segment register Extra segment register Flag register Instruction pointer 611 37100 微處理機原理與應用 Lecture 04-24 12

4.3 The PC and Its DEBUG Program Status flag notations Flag Meaning Set Reset OF Overflow OV NV DF Direction DN UP IF Interrupt EI DI SF Sign NG PL ZF Zero ZR NZ AF Auxiliary carry AC NA PF Parity PE PO CF Carry CY NC 611 37100 微處理機原理與應用 Lecture 04-25 4.3 The PC and Its DEBUG Program Issue commands to the DEBUG program on the PC that causes the value in BX to be modified to FF00 16 and then verify that this new value is loaded into BX. -R BX ( ) BX 0000 :FF00 ( ) -R BX ( ) BX FF00 :_ ( ) _ 611 37100 微處理機原理與應用 Lecture 04-26 13

4.3 The PC and Its DEBUG Program Use the Register command to set the parity flag to even parity. Verify that the flag has been changed. -R F ( ) NV UP EI PL NZ NA PO NC -PE ( ) -R F ( ) NV UP EI PL NZ NA PE NC - ( ) 611 37100 微處理機原理與應用 Lecture 04-27 4.4 Examining and Modifying the Contents of Memory The commands provided for use in examining and modifying the memory: DUMP ENTER FILL MOVE COMPARE SERACH 611 37100 微處理機原理與應用 Lecture 04-28 14

4.4 Examining and Modifying the Contents of Memory DUMP Command (D) The DUMP command allows us to examine the contents of a memory location or a block of consecutive memory location. D [ADDRESS] e.g. -D ( ) -D 1342:100 ( ) -D DS:100 ( ) -D 100 ( ) 611 37100 微處理機原理與應用 Lecture 04-29 4.4 Examining and Modifying the Contents of Memory DUMP Command (D) Address of the first byte of data ASCII version of the memory data 611 37100 微處理機原理與應用 Lecture 04-30 16 bytes of data per line, 128 bytes per dump 15

4.4 Examining and Modifying the Contents of Memory Issue a dump command to display the contents of the 32 bytes of memory located at offset 0300 16 through 031F 16 in the current data segment. -D 300 31F ( ) 611 37100 微處理機原理與應用 Lecture 04-31 4.4 Examining and Modifying the Contents of Memory Use the Dump command to examine the 16 bytes of memory just below the top of the stack. -D SS:FFEE FFFD ( ) 611 37100 微處理機原理與應用 Lecture 04-32 16

4.4 Examining and Modifying the Contents of Memory ENTER Command (E) E ADDRESS [LIST] e.g. -E DS:100 FF FF FF FF FF ( ) -E DS:100 ( ) -1342:0100 FF. _ ( ) (Return to end) -E DS:100 ( ) -1342:0100 FF. _ (Space bar to continue) -1342:0100 FF. FF._ 611 37100 微處理機原理與應用 Lecture 04-33 4.4 Examining and Modifying the Contents of Memory Start a data entry sequence by examining the contents of address DS:100 and then, without entering new data, depress the - key. What happen? -E DS:100 ( ) 1342:0100 FF. _ Entering - causes the display of previous byte storage location. 611 37100 微處理機原理與應用 Lecture 04-34 17

4.4 Examining and Modifying the Contents of Memory Enter ASCII data to the memory. -E DS:200 ASCII ( ) -E DS:200 ASCII ( ) 611 37100 微處理機原理與應用 Lecture 04-35 4.4 Examining and Modifying the Contents of Memory FILL Command (F) The FILL command fills a block of consecutive memory locations all with the same data. F STARTING_ADDRESS ENDING_ADDRESS LIST e.g. -F 100 11F 22 ( ) 611 37100 微處理機原理與應用 Lecture 04-36 18

4.4 Examining and Modifying the Contents of Memory Initialize all storage locations in the block of memory from DS:120 through DS:13F with the value 33 16 and the block of storage locations from DS:140 to DS:15F with the value 44 16. -F 120 13F 33 ( ) -F 140 15F 44 ( ) 611 37100 微處理機原理與應用 Lecture 04-37 4.4 Examining and Modifying the Contents of Memory MOVE Command (M) The MOVE command allows us to copy a block of data from one part of memory to another part. M START_ADDRESS END_ADDRESS DEST_ADDRESS e.g. -M 100 11F 200 ( ) 611 37100 微處理機原理與應用 Lecture 04-38 19

4.4 Examining and Modifying the Contents of Memory Fill each storage location in the block of memory from address DS:100 through DS:11F with the value 11 16. Then copy this block of data to a destination block starting at DS:160. -F 100 11F 11 ( ) -M 100 11F 160 ( ) 611 37100 微處理機原理與應用 Lecture 04-39 4.4 Examining and Modifying the Contents of Memory COMPARE Command (C) The COMPARE command allows us to compare the contents of two blocks of data to determine if they are or are not the same. C START_ADDRESS END_ADDRESS DEST_ADDRESS e.g. -C 100 10F 120 ( ) 611 37100 微處理機原理與應用 Lecture 04-40 20

4.4 Examining and Modifying the Contents of Memory COMPARE Command (C) Results produced when unequal data are found with a COMPARE command 611 37100 微處理機原理與應用 Lecture 04-41 4.4 Examining and Modifying the Contents of Memory SEARCH Command (S) The SEARCH command can be used to scan through a block of data in memory to determine whether or not it contains specific data. C START_ADDRESS END_ADDRESS LIST e.g. -S 100 17F 33 ( ) 611 37100 微處理機原理與應用 Lecture 04-42 21

4.4 Examining and Modifying the Contents of Memory SEARCH Command (S) 611 37100 微處理機原理與應用 Lecture 04-43 4.5 Input and Output of Data INPUT Command (I) The INPUT command read data from an input port of the 64K byte-wide ports of 8088 I/O. I ADDRESS e.g. -I 61 ( ) 4D The contents of the port ant I/O address 0061 16 are 4D 16 611 37100 微處理機原理與應用 Lecture 04-44 22

4.5 Input and Output of Data OUTPUT Command (O) The OUTPUT command write data to an input port of the 64K byte-wide ports of 8088 I/O. O ADDRESS BYTE e.g. -O 61 4F ( ) This command causes the value 4F 16 to be written into the byte-wide output port at address 0061 16 611 37100 微處理機原理與應用 Lecture 04-45 4.6 Hexadecimal Addition and Subtraction HEXADECIMAL Command (H) The HEXADECIMAL command provides the ability to add and subtract hexadecimal numbers. H NUM1 NUM2 e.g. -H ABC0 0FFF ( ) BBBF 9BC1 -H BBBF A ( ) BBC9 BBB5 *Both number and results are limited to four hexadecimal digits. 611 37100 微處理機原理與應用 Lecture 04-46 23

4.6 Hexadecimal Addition and Subtraction Use the H command to find the negative of the number 0009 16. -H 0 9 ( ) 0009 FFF7 FFF7 16 is the negative of 9 16 expressed in 2 s complement form. 611 37100 微處理機原理與應用 Lecture 04-47 4.6 Hexadecimal Addition and Subtraction If a byte of data is located at physical address 02A34 16 and the data segment register contains 0150 16, what value must be loaded into the source index register such that DS:SI points to the byte storage location? -H 2A34 1500 ( ) 3F34 1534 This shows that SI must be loaded with the value 1534 16. 611 37100 微處理機原理與應用 Lecture 04-48 24

4.7 Loading, Verifying and Saving Machine Language Program An example to load an instruction MOV BL, AL The machine code is 88C3 16 -E CS:100 88 C3 ( ) -D CS:100 101 ( ) 1342:0100 88 C3 611 37100 微處理機原理與應用 Lecture 04-49 4.7 Loading, Verifying and Saving Machine Language Program UNASSEMBLE Command (U) The UNASSEMBLE command converts machine code instructions to their equivalent assembly language source statement. U [STARTING_ADDRESS [ENDING_ADDRESS] ] e.g. -U CS:100 101 ( ) 1342:0100 88C3 MOV BL, AL 611 37100 微處理機原理與應用 Lecture 04-50 25

4.7 Loading, Verifying and Saving Machine Language Program Use a sequence of commands to load, verify loading, and unassemble the machine code instruction 0304H. Load the instruction at address CS:200. -E CS:200 03 04 ( ) -D CS:200 201 ( ) -U CS:200 201 ( ) ADD AX, [SI] 611 37100 微處理機原理與應用 Lecture 04-51 4.7 Loading, Verifying and Saving Machine Language Program WRITE Command (W) The WRITE command gives the ability to save data stored in memory on a diskette. W [START_ADDRESS [DRIVE START_SECTOR NUM_SECTOR] ] e.g. -W CS:200 1 10 1 ( ) -W 200 1 10 1 ( ) Drive B 1 Sector = 512 Byte * Be caution in saving program in a disk, especially the hard drive. 611 37100 微處理機原理與應用 Lecture 04-52 26

4.7 Loading, Verifying and Saving Machine Language Program LOAD Command (L) The LOAD command gives the ability to reload memory from a diskette. L [START_ADDRESS [DRIVE START_SECTOR NUM_SECTOR] ] e.g. -L CS:300 1 10 1 ( ) The reloading of the instruction can be verified by U command e.g. -U CS:300 301 ( ) 1342:300 301 ADD AX, [SI] 611 37100 微處理機原理與應用 Lecture 04-53 4.7 Loading, Verifying and Saving Machine Language Program Enter the machine code of the block move program. The program is to be loaded into memory starting at address CS:100. Verify, unassemble, and save the code. -E CS:100 B8 00 20 8E D8 BE 00 01 BF 20 01 B9 10 00 8A 24 88 25 46 ( ) -D CS:100 117( ) -U CS:100 117( ) -W CS:100 1 100 1 ( ) 611 37100 微處理機原理與應用 Lecture 04-54 27

4.7 Loading, Verifying and Saving Machine Language Program 611 37100 微處理機原理與應用 Lecture 04-55 4.7 Loading, Verifying and Saving Machine Language Program NAME Command (N) The NAME command, along with the WRITE command, gives the ability to save a program on the diskette under a file name. N FILE NAME The BX, CX registers must be updated to identify the size of the program that is to be saved in the file. After BX, CX registers have been initialized, the write command is used to saved the program. To reload the program, the command sequence is N FILE NAME L [STARTING ADDRESS] 611 37100 微處理機原理與應用 Lecture 04-56 28

4.7 Loading, Verifying and Saving Machine Language Program Save a machine code program into a file. -N A:BLK.1 ( ) ; Give a file name in disk A -R CX ( ) ; Give a program size of 18 16 bytes CX XXXX :18 -R BX ( ) BX XXXX :0 ( ) W CS:100 ( ) ; Save the program in disk A 611 37100 微處理機原理與應用 Lecture 04-57 4.7 Loading, Verifying and Saving Machine Language Program Reload a program into memory. -N A:BLK.1 ( ) ; Give a file name in disk A -L CS:100 ( ) ; Load the program name BLK.1 in disk A C:\DOS>REN A:BLK.1 BLK.EXE ( ) ; Rename the file C:\DOS>DEBUG A:BLK.EXE ( ) ; Load the program directly C:\DOS>A:BLK.EXE ( ) ; Run the program 611 37100 微處理機原理與應用 Lecture 04-58 29

4.8 Assembling Instructions with the Assemble Command ASSEMBLE Command (A) The ASSEMBLE command let us automatically assemble the instructions of a program. A [STARTING_ADDRESS] e.g. -A CS:100 ( ) 1342:0100 _ 1342:0100 ADD [BX+SI+1234], AX ( ) 1342:0104 _ -D CS:100 103 ( ) 611 37100 微處理機原理與應用 Lecture 04-59 4.8 Assembling Instructions with the Assemble Command Assemble a complete program with the ASSEMBLE command. -A CS:200 ( ) 0B35:0200 MOV AX, 2000 ( ) 0B35:0203 MOV DS, AX ( ) 0B35:0205 MOB SI, 100 ( )........ 0B35:0217 NOP ( ) 0B35:0218 ( ) 611 37100 微處理機原理與應用 Lecture 04-60 30

4.8 Assembling Instructions with the Assemble Command Assemble a program with ASSEMBLE command 611 37100 微處理機原理與應用 Lecture 04-61 4.8 Assembling Instructions with the Assemble Command Unassemble a program with UNASSEMBLE command 611 37100 微處理機原理與應用 Lecture 04-62 31

4.9 Executing Instructions and Programs with the TRACE and GO command TRACE Command (T) The TRACE command provides the programmer with the ability to execute the program one instruction at a time. T [=STARTING_ADDRESS] [NUMBER] e.g. -T =CS:100 ( ) -T ( ) -T =CS:100 3 ( ) 611 37100 微處理機原理與應用 Lecture 04-63 4.9 Executing Instructions and Programs with the TRACE and GO command Load and trace a program. -L CS:100 1 10 1 ( ) -U 100 101 ( ) -R AX ( ) AX 0000 :1111 ( ) -R SI ( ) SI 0000 :1234 ( ) -E DS:1234 22 22 ( ) -T =CS:100 ( ) 611 37100 微處理機原理與應用 Lecture 04-64 32

4.9 Executing Instructions and Programs with the TRACE and GO command 611 37100 微處理機原理與應用 Lecture 04-65 4.9 Executing Instructions and Programs with the TRACE and GO command GO Command (G) The GO command is typically used to run programs that are already working or to execute programs in the later stages or debugging. G [=STARTING_ADDRESS [BREAKPOINT_ADDRESS_LIST] ] e.g. -G =CS:200 217 ( ) -G =CS:100 ( ) -G ( ) 611 37100 微處理機原理與應用 Lecture 04-66 33

4.9 Executing Instructions and Programs with the TRACE and GO command Use GO command to execute a program and examine the result. -N A:BLK.EXE ( ) ; Define the program file to be loaded -L CS:200 ( ) ; Load the program at CS:200 -R DS ( ) DS 1342 :2000 ( ) ; Define the data segment address -F DS:100 10F FF ( ) ; Fill memory with FF -F DS:120 12F 00 ( ) ; Fill memory with 00 -R DS ( ) DS 2000 :1342 ; Store data segment with 1342 16 611 37100 微處理機原理與應用 Lecture 04-67 4.9 Executing Instructions and Programs with the TRACE and GO command Use GO command to execute a program and examine the result. (continued) -R ( ) ; Show data register status -U CS:200 217 ( ) ; Unassemble the program -G =CS:200 20E ( ) ; Execute the program to CS:20E -G =CS:20E 215 ( ) ; Execute the program to CS:215 -D DS:100 10F ( ) ; Display memory at DS:100 -D DS:120 12F ( ) ; Display memory at DS:120 -G =CS:215 217 ( ) ; Execute the program to CS:217 -D DS:100 10F ( ) ; Display memory at DS:100 -D DS:120 12F ( ) ; Display memory at DS:120 611 37100 微處理機原理與應用 Lecture 04-68 34

4.9 Executing Instructions and Programs with the TRACE and GO command 611 37100 微處理機原理與應用 Lecture 04-69 4.9 Executing Instructions and Programs with the TRACE and GO command 611 37100 微處理機原理與應用 Lecture 04-70 35

4.9 Executing Instructions and Programs with the TRACE and GO command 611 37100 微處理機原理與應用 Lecture 04-71 4.10 Debugging a Program Errors in a program are also referred to as bugs; the process of removing them is called debugging. Two types of errors Syntax error Execution error A syntax error is an error caused by not following the rules for coding or entering an instruction. These types of errors are typically identified by the microcomputer and signaled to user with an error message In the DEBUG environment, the TRACE command is usually used to debug execution errors. 611 37100 微處理機原理與應用 Lecture 04-72 36

4.10 Debugging a Program Review of the DEBUG commands 611 37100 微處理機原理與應用 Lecture 04-73 37