Assembly x86程序集转换基数
跟进先前的问题。我正在尝试用x86编写两个过程。一个过程在一个特定的基中读入一个integer ReadInteger,然后在另一个基中将其写出WriteInteger。我所挣扎的地方更多的是解决方案,而不是实际的代码 首先,ReadInteger可以从任何基数(例如1234,基数5)中获取一个数字。然后WriteInteger必须能够在eax中获取该整数,在bl中获取一个新的基值,并将其转换为新的基值。我想问的是,我是否需要将ReadInteger过程或另一个过程中的所有内容转换为公共基(比如十进制),然后再进行转换,因为我只能在WriteInteger中接收整数和新的基值?还有别的我错过的路吗?我似乎想不出任何其他的方法来做这件事,但是作业看起来应该比这个简单 这是到目前为止我的代码Assembly x86程序集转换基数,assembly,x86,Assembly,X86,跟进先前的问题。我正在尝试用x86编写两个过程。一个过程在一个特定的基中读入一个integer ReadInteger,然后在另一个基中将其写出WriteInteger。我所挣扎的地方更多的是解决方案,而不是实际的代码 首先,ReadInteger可以从任何基数(例如1234,基数5)中获取一个数字。然后WriteInteger必须能够在eax中获取该整数,在bl中获取一个新的基值,并将其转换为新的基值。我想问的是,我是否需要将ReadInteger过程或另一个过程中的所有内容转换为公共基(比如
;-----------------------------------------------------
ReadInteger PROC
;
; ReadInteger is passed one argument in bl representing the base of the number to be input.
; Receives: bl register (original base)
; Returns: EAX
;-----------------------------------------------------
nextChar:
mov edx, 0 ; prepare for divide
mov base, ebx
call ReadChar ; Get the next keypress
call WriteChar ; repeat keypress
call AsciiToDigit
div base
shl ebx,1 ; shift to make room for new bit
or ebx,base ; set the bit to eax
cmp al, 13 ; check for enter key
jne nextChar
mov eax, ebx ; place integer value in eax for return
ret
ReadInteger ENDP
;-----------------------------------------------------
WriteInteger PROC
;
; Will display a value in a specified base
; Receives: EAX register (integer), bl (new base)
; Returns: nothing
;-----------------------------------------------------
mov ecx, 0 ; count the digits
nextDigit:
mov edx, 0 ; prepare unsigned for divide
div ebx
push edx ; remainder will be in dl
inc ecx ; count it!
cmp eax, 0 ; done when eax becomes 0
jne nextDigit
; pop them off and convert to ASCII for output
outDigit:
pop eax ; digits come off left to right
add eax, '0' ; add 0 to get ASCII
call WriteChar
loop outDigit
call Crlf
ret
ret
寄存器中的WriteInteger ENDP数字没有特定的基,它们只是二进制数。基数是人类用来使数字更具可读性的东西。这意味着基本概念仅适用于输入和输出,而不适用于机器内部。有些奇怪的例外情况,比如BCD,你最终可能会遇到,但今天不会
因此,用特定基址读取和用特定基址写入的函数是完全独立的,它们之间需要传递的唯一信息是二进制数本身。寄存器中的数字没有特定的基址,它们只是二进制数。基数是人类用来使数字更具可读性的东西。这意味着基本概念仅适用于输入和输出,而不适用于机器内部。有些奇怪的例外情况,比如BCD,你最终可能会遇到,但今天不会
因此,用特定基址读取和用特定基址写入的函数是完全独立的,它们之间需要传递的唯一信息就是二进制数本身。为什么不先用高级语言解决这个问题?x86汇编语言不是一种很好的数学算法原型语言。为什么不先用高级语言解决这个问题呢?x86汇编语言不是一种很好的数学算法原型语言,我想这是我所缺少的。所以这个值是以二进制形式存储在寄存器中的,但我仍然需要将它从ASCII字符转换为ReadInteger函数中的实际二进制值,对吗?这就是我认为缺少的。因此,该值以二进制形式存储在寄存器中,但我仍然需要将其从ASCII字符转换为ReadInteger函数中的实际二进制值,对吗?