本文介绍了汇编语言新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是汇编语言编程的新手,我希望我的输出具有单独的行,以便于阅读,但是,我编写了代码并使它工作,但随后得知我不能实际上,使用Irvine程序进行了换行.我的教科书仅使用Irvine的"Crlf",而在此网站上提出类似问题的其他人的代码完全破坏了我的程序,因此我迷路了.

I'm brand new to assembly language programming, and I would like my output to have separate lines so that it is easier to read, however, I wrote my code and had it working, but was then informed that I could not in fact use the Irvine procedure to make a new line. My text book only uses the Irvine "Crlf" and the code from other people who asked similar questions on this website completely broke my program so now I'm lost.

我尝试过的是:

mov ah, 0Eh       ;print new line sequence
mov al, 0Dh
int 10h
mov al, 0Ah
int 10h

无论如何,这是我完整的代码,还有Irvine函数.有人可以在不使用"call Crlf"的情况下帮助我获得所需的输出吗?还是让我知道为什么上面的代码破坏了我的程序?我敢肯定我有什么想念的.

Anyways, here is my complete code with the Irvine function still. Can someone help me get the output I'm looking for without using the "call Crlf"? Or let me know why the code above is breaking my program? I'm sure there's something I'm missing.

INCLUDE Irvine32.inc


.data
prompt BYTE 'Enter a positive integer: ', 0
report1 BYTE 'The sum is: ', 0
report2 BYTE 'The product is: ', 0
report3 BYTE 'The power result is: ', 0
temp DWORD ? ;
.code

main PROC
; Main program control procedure.
; Calls: GetInteger, AddNumbers, MultiplyNumbers,
;       WriteInt, CalculatePower

call GetInteger             ;Get the first user entered integer
mov ebx, eax                ;Store the value into the EBX register
call GetInteger             ;Get the second user entered integer
mov temp,eax                ;Copy the value into temp for holding
call AddNumbers             ;Find the sum of the two integers
mov edx,OFFSET report1      ;Display sum result
call WriteString
call WriteInt
mov eax, temp               ;Replace the EAX value with the second user entered integer
call MultiplyNumbers        ;Find the product of the two integers
call Crlf                   ;New line
mov edx,OFFSET report2      ;Display the product result
call WriteString
call WriteInt
mov eax, temp               ;Replace the EAX value with the second user entered integer
call CalculatePower         ;Find the power result of the two integers
call Crlf                   ;New line
mov edx,OFFSET report3      ;Display the power result
call WriteString
call WriteInt
    exit                    ;exit to operating system
main ENDP

;-------------------------------------------------------------
GetInteger PROC
;
; Prompts the user for two integers and stores
; them into EAX and EBX registers
; Receives: Doubleword integers
; Returns: The two integer values in the EAX and EBX registers
; Calls: WriteString, ReadInt
;----------------------------------------------------------------
    mov edx,OFFSET prompt   ;Prompt user for integer entry
    call WriteString
    call ReadInt
    ret
GetInteger ENDP

;-----------------------------------------------------------------
AddNumbers PROC
;
; Calculates the sum of two 32-bit integers
; Receives: The integer values in the registers EAX and EBX
; Returns: The sum in the EAX register
; Calls: none
;------------------------------------------------------------------
    add eax,ebx         ;Find the sum
    ret
AddNumbers ENDP

;--------------------------------------------------------------------
MultiplyNumbers PROC
;
; Calculates the product of two 32-bit integers
; Receives: The integer values in the registers EAX and EBX
; Returns: The product in the EAX register
; Calls: none
;---------------------------------------------------------------------
    mul ebx             ;Find the product
    ret
MultiplyNumbers ENDP

;--------------------------------------------------------------------
CalculatePower PROC
;
; Calculates the result of the first 32 bit integer to the power
; of the second by using MultiplyNumbers
; Receives: The result of MultiplyNumbers
; Returns: The power result in EAX register
; Calls: MultiplyNumbers
;---------------------------------------------------------------------
    mov ecx,eax         ;Set the counter with the value of the second integer
    sub ecx, 1          ;Subtract one so the counter calls MultiplyNumbers the correct amount
    mov eax,ebx         ;Copy EBX into EAX so that MultiplyNumbers finds the power result

    FindPower:
        call MultiplyNumbers;Find the power result
        loop FindPower  ;Repeat the loop till the count is 0

    ret
CalculatePower ENDP

END main

推荐答案

CRLF只是两个字节的序列,添加到输出中,分别是值13和10.

CRLF is just a sequence of two bytes added to the output, the values 13 and 10.

如果您使用这两个值(也许是prompt BYTE 'Hello!', 13, 10, 0或仅由cr/lf 13,10,0组合组成)组成了字符串,则无需特殊过程即可输出它.

If you made a string with those two values, perhaps prompt BYTE 'Hello!', 13, 10, 0 or just consisting of the cr/lf 13,10,0 combo, you can output it without a special procedure.

这篇关于汇编语言新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 19:03