簡體   English   中英

匯編語言新行

[英]Assembly Language New Line

我是匯編語言編程的新手,我希望我的輸出具有單獨的行,以便於閱讀,但是,我編寫了代碼並使它工作,但隨后得知我實際上無法使用Irvine程序以換行。 我的教科書僅使用Irvine的“ Crlf”,而在此網站上提出類似問題的其他人的代碼完全破壞了我的程序,因此我迷路了。

我嘗試過的是:

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

無論如何,這是我完整的帶有Irvine函數的代碼。 有人可以在不使用“ call Crlf”的情況下幫助我獲得所需的輸出嗎? 還是讓我知道為什么上面的代碼破壞了我的程序? 我敢肯定我缺少什么。

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。

如果使用這兩個值創建了字符串,可能會prompt BYTE 'Hello!', 13, 10, 0輸入BYTE'Hello prompt BYTE 'Hello!', 13, 10, 0 13、10、0或僅由cr / lf 13,10,0組合組成,則無需特殊過程即可輸出它。

為了擴展亞當的答案,這可能正是您要尋找的內容:

carriageReturn BYTE ' ', 13, 10, 0

然后將其稱為:

mov edx,OFFSET report1       ;Display sum result
call WriteString
call WriteInt
mov edx,OFFSET carriageReturn ; new line
call WriteString

這樣,回車在WriteInt之后

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM