查找不在0到n的数字
Problem: Write a program in 8086 microprocessor to find out the largest among 8-bit n numbers, where size n is stored at memory address 2000 : 500 and the numbers are stored from memory address 2000 : 501 and store the result (largest number) into memory address 2000 : 600.
问题: 在8086微处理器中编写一个程序,以找出8位n个数字中最大的一个 ,其中大小n存储在内存地址2000:500中,数字从存储地址2000:501存储并存储结果(最大数字)进入内存地址2000:600。
Algorithm:
算法:
Load data from offset 500 to register CL and set register CH to 00 (for count).
将数据从偏移500加载到寄存器CL并将寄存器CH设置为00(用于计数)。
Load first number (value) from next offset (i.e. 501) to register AL and decrease count by 1.
从下一个偏移量(即501)中加载第一个数字(值)到寄存器AL,并将计数减1。
Now compare value of register AL from data(value) at next offset, if that data is greater than value of register AL then update value of register AL to that data else no change, and increase offset value for next comparison and decrease count by 1 and continue this till count (value of register CX) becomes 0.
现在将寄存器AL的值与下一个偏移量的数据(值)进行比较,如果该数据大于寄存器AL的值,则将寄存器AL的值更新为该数据,否则保持不变,并为下一次比较将偏移量值增加,并将计数减少1并继续进行直到计数(寄存器CX的值)变为0。
Store the result (value of register AL) to memory address 2000 : 600.
将结果(寄存器AL的值)存储到内存地址2000:600。
Program:
程序:
ADDRESS | MNEMONICS | COMMENTS |
---|---|---|
400 | MOV SI, 500 | SI ← 500 |
403 | MOV CL, [SI] | CL ← [SI] |
405 | MOV CH, 00 | CH ← 00 |
407 | INC SI | SI ← SI+1 |
408 | MOV AL, [SI] | AL ← [SI] |
40A | DEC CL | CL ← CL-1 |
40C | INC SI | SI ← SI+1 |
40D | CMP AL, [SI] | AL-[SI] |
40F | JNC 413 | JUMP TO 413 IF CY=0 |
411 | MOV AL, [SI] | AL ← [SI] |
413 | INC SI | SI ← SI+1 |
414 | LOOP 40D | CX ← CX-1 & JUMP TO 40D IF CX NOT 0 |
416 | MOV [600], AL | AL → [600] |
41A | HLT | END |
地址 | 记忆 | 注释 |
---|---|---|
400 | MOV SI,500 | SI←500 |
403 | MOV CL,[SI] | CL←[SI] |
405 | MOV CH,00 | CH←00 |
407 | INC SI | SI←SI + 1 |
408 | MOV AL,[SI] | AL←[SI] |
40A | DEC CL | CL←CL-1 |
40度 | INC SI | SI←SI + 1 |
40D | CMP AL,[SI] | AL- [SI] |
40楼 | JNC 413 | 如果CY = 0,则跳至413 |
411 | MOV AL,[SI] | AL←[SI] |
413 | INC SI | SI←SI + 1 |
414 | 环40D | 如果CX不为0,则CX←CX-1和跳至40D |
416 | MOV [600],AL | AL→[600] |
41A | HLT | 结束 |
Explanation:
说明:
MOV SI, 500: set the value of SI to 500
MOV SI,500:将SI的值设置为500
MOV CL, [SI]: load data from offset SI to register CL
MOV CL,[SI]:将数据从偏移SI加载到寄存器CL
MOV CH, 00: set value of register CH to 00
MOV CH,00:将寄存器CH的值设置为00
INC SI: increase value of SI by 1
INC SI:将SI的值增加1
MOV AL, [SI]: load value from offset SI to register AL
MOV AL,[SI]:从偏移量SI到寄存器AL的加载值
DEC CL: decrease value of register CL by 1
DEC CL:将寄存器CL的值减1
INC SI: increase value of SI by 1
INC SI:将SI的值增加1
CMP AL, [SI]: compares value of register AL and [SI] (AL-[SI])
CMP AL,[SI]:比较寄存器AL和[SI](AL- [SI])的值
JNC 413: jump to address 413 if carry not generated
JNC 413:如果未生成进位则跳转到地址413
MOV AL, [SI]: transfer data at offset SI to register AL
MOV AL,[SI]:将偏移量SI的数据传输到寄存器AL
INC SI: increase value of SI by 1
INC SI:将SI的值增加1
LOOP 40C: decrease value of register CX by 1 and jump to address 40D if value of register CX is not zero
LOOP 40C:如果寄存器CX的值不为零,则将寄存器CX的值减1并跳转到地址40D
MOV [600], AL: store the value of register AL to offset 600
MOV [600],AL:将寄存器AL的值存储到偏移600
HLT: stop
HLT:停止
翻译自: https://www.includehelp.com/embedded-system/find-the-largest-among-8-bit-N-numbers.aspx
查找不在0到n的数字