8086 程式確定兩個陣列中對應元素的減法
在本程式中,我們將瞭解如何減去兩個不同陣列的內容。
問題陳述
編寫 8086 組合語言程式,以減去儲存在兩個不同陣列中對應的元素的內容
討論
此示例中有兩個不同的陣列。陣列儲存在 501 及其以後的位置和 601 及其以後的位置。這兩個陣列的大小儲存在偏移位置 500。我們使用陣列大小初始化計數器,然後透過使用迴圈逐個減去元素
輸入
地址 | 資料 |
---|---|
… | … |
500 | 04 |
501 | 09 |
502 | 03 |
503 | 08 |
504 | 06 |
… | … |
601 | 04 |
602 | 01 |
603 | 02 |
604 | 03 |
… | … |
流程圖
程式
MOV SI, 500 ;Point Source index to 500 MOV CL, [SI] ;Load the array size into CL MOV CH, 00 ;Clear Upper half of CX INC SI ;Increase SI register to point next location MOV DI, 601 ;Destination register points to 601 L1: MOV AL, [SI] ;Load A with the data stored at SI SUB AL, [DI] ;Subtract DI element from AL MOV [SI], AL ;Store AL to SI address INC SI ;SI Point to next location INC DI ;DI Point to next location LOOP L1 ;Jump to L1 until the counter becomes 0 HLT ;Terminate the program
輸出
地址 | 資料 |
---|---|
… | … |
500 | 04 |
501 | 05 |
502 | 02 |
503 | 06 |
504 | 03 |
… | … |
廣告