2013-04-20 93 views
0

彙編語言8086:我們可以一次使用兩個32位寄存器(32 + 32 = 64)來使其能夠讀取64位的值嗎?彙編語言8086

我不得不做出另外它需要在控制檯的兩個值,給我們造成..就只能採取下32位(8位),如果我們給予較高的值,則值的程序它會給控制檯上的整數溢出錯誤

如果我想在輸入1和輸入2中給出更多的32位值,我該怎麼做?

我想使用32位寄存器將值value1添加到value2並給出64位(等於16位數)下的值..可以使用2 reg(32 + 32 = 64位)的空間嗎? ...

我們如何能2寄存器32位,使其64位我知道這是可能的,但我不知道怎麼做了......因爲我在彙編語言是新

我正在使用匯編語言的KIP.R.IRVINE鏈接庫

我們如何通過使用2 32位reg來提供64位值?或者我們如何讓2位32位寄存器取得64位的值?

這裏是32位加法代碼:

INCLUDE Irvine32.inc 

.data 

Addition BYTE "A: Add two Integer Numbers", 0 

inputValue1st BYTE "Input the 1st integer = ",0 
inputValue2nd BYTE "Input the 2nd integer = ",0 

    outputSumMsg BYTE "The sum of the two integers is = ",0 

    num1 DD ? 
    num2 DD ? 
    sum DD ? 

    .code 

    main PROC 

    ;----Displays addition Text----- 

    mov edx, OFFSET Addition 
    call WriteString 
    call Crlf 
    ;------------------------------- 

    ; calling procedures here 

    call InputValues 
    call addValue 
    call outputValue 

    call Crlf 

    jmp exitLabel 


    main ENDP 


     ; the PROCEDURES which i have made is here 


    InputValues PROC 
    ;----------- For 1st Value-------- 


    call Crlf 
    mov edx,OFFSET inputValue1st ; input text1 
    call WriteString 

    ; here it is taking 1st value 
    call ReadInt ; read integer 
    mov num1, eax ; store the value 




    ;-----------For 2nd Value---------- 



     mov edx,OFFSET inputValue2nd ; input text2 
     call WriteString 


     ; here it is taking 2nd value 
     call ReadInt ; read integer 
     mov num2, eax ; store the value 

     ret 
     InputValues ENDP 




    ;---------Adding Sum---------------- 

    addValue PROC 
    ; compute the sum 

    mov eax, num2 ; moves num2 to eax 
    add eax, num1 ; adds num2 to num1 
    mov sum, eax ; the val is stored in eax 

    ret 
    addValue ENDP 

    ;--------For Sum Output Result---------- 

    outputValue PROC 

    ; output result 

    mov edx, OFFSET outputSumMsg ; Output text 
    call WriteString 


    mov eax, sum 
    call WriteInt ; prints the value in eax 


    ret 
    outputValue ENDP 


    exitLabel: 
    exit 


    END main 
+3

8086沒有32位寄存器,如'eax'和'edx'。你想創建32位386+代碼還是8086+的16位代碼?你在你的代碼中使用'eax'和'edx',但要求8086的解決方案。這不是一致的。 – nrz 2013-04-20 23:52:58

回答

1

您可以結合使用ADCADD做某些內容添加到存儲在2個32位寄存器,64位整數。

您可以使用SHLDSHL一起向左移動存儲在2個32位寄存器中的64位整數。

如果可以執行64位加法和64位移位,則可以輕鬆地將64位整數乘以10(hint: 10=8+2, x*10=x*8+x*2)。

您可能需要它才能從控制檯讀取64位整數。您需要將它們讀取爲ASCII strings,然後使用重複乘法10和加法(hint: 1234 = (((0+1)*10+2)*10+3)*10+4)將其轉換爲64位整數。

上面應該有足夠的信息來讀取64位整數並添加它們。

爲了打印總和,您需要將64位除以10,以便將64位整數轉換爲ASCII string的十進制表示形式(hint: 4=1234 mod 10 (then 123 = 1234/10), 3 = 123 mod 10 (then 12 = 123/10), 2 = 12 mod 10 (then 1 = 12/10), 1 = 1 mod 10 (then 0 = 1/10, stop))。

我現在不打算解釋如何使用2 DIVs通過10來執行64位除法。讓其他人先工作。