简体   繁体   English

汇编寄存器比较(8086)

[英]Assembly register compares (8086)

I am new to assembly and creating a program that takes a value in the AX register, say F43A , and converts it to its ascii string in decimal. 我是组装和创建程序的新手,该程序在AX寄存器中使用一个值,例如F43A ,并将其转换为十进制的ascii字符串。

For instance, AX = 8EFFh would print out -28929 . 例如, AX = 8EFFh将输出-28929 (Convert 2s complement to ascii) (将2s补码转换为ascii)

I am having trouble with comprehending the registers. 我在理解寄存器时遇到了麻烦。 Do I have to convert the AX register to decimal first, or is that implied that if AX = 000Ah in hex that AX is also equal to 10 in decimal. 我必须转换AX先登记为十进制,或者说是暗示,如果AX = 000Ah十六进制即AX也是十进制等于10。

So does 也是

mov AX,000Ah
cmp AX,10

work? 工作?

Any help would be appreciated. 任何帮助,将不胜感激。 We will be using the reduction of powers algorithm, which will be based off the decimal value of AX . 我们将使用降低功率算法,该算法基于AX的十进制值。 Though the input value of AX will be in Hex. 尽管AX的输入值为十六进制。

If that doesn't work, how would I get the decimal value out of AX ? 如果那不起作用,我如何从AX获取十进制值?

CPUs fundamentally know only binary. CPU从根本上只知道二进制。 The assembler, compiler or disassembler only provide convenience utilities to assist inputting or outputting the data in higher levels of abstraction (such as grouping to hex-digits or decimals, signed or unsigned, floating points and instructions such as cmp ax, 10 ). 汇编器,编译器或反汇编器仅提供便利实用程序,以协助以较高抽象级别输入或输出数据(例如,分组为十六进制数字或十进制,有符号或无符号,浮点数和指令,例如cmp ax, 10 )。

Both cmp ax, 10 and some variety of cmp ax, 0x0a or cmp ax, $a or cmp ax, 000ah all encode to the same instruction: xx 0a . cmp ax, 10和各种cmp ax, 0x0acmp ax, $acmp ax, 000ah都编码为同一指令: xx 0a

Your task indeed is using instructions knowing only "numbers" split a 16-bit number (eg 8EFF) to it's components (array of length 1..5) and output it using ASCII conversion. 您的任务确实是在使用仅知道“数字”的16位数字(例如8EFF)拆分为其组件(长度为1..5的数​​组)并使用ASCII转换输出的指令。

When implementing the reduction of powers algorithm, notice that the 8086 DIV instructions use the register pair DX:AX as the input. 当执行功耗降低算法时,请注意8086 DIV指令使用寄存器对DX:AX作为输入。

You can get the digits in reverse order by dividing by 10, then the remainder is the last digit, then divide by 10 again, the remainder is the next to last digit, ... 您可以按相反的顺序将数字除以10,然后余数为最后一位数字,然后再除以10,则余数为最后一位的倒数第二位,...

or you can divide by 10,000 and the quotient is the first digit unless it's zero. 或者您可以除以10,000,并且商是第一个数字,除非它为零。 Then divide the remainder by 1000, and the quotient is the next digit, ... 然后将余数除以1000,商就是下一位,...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM