【问题标题】:readint function help... ?(MASM)readint 函数帮助...?(MASM)
【发布时间】:2014-10-18 16:58:27
【问题描述】:

我正在尝试完成一个 MASM 程序。这是我的目标(我的作业)。

将第 5.6.1 节(第 173-175 页)中的 Summation 程序修改如下:使用常量选择数组大小:

ARRAY_SIZE = 20

array DWORD ARRAY_SIZE DUP(?)

编写一个新过程,提示用户输入要处理的整数个数。将相同的内容传递给 PromptForIntegers 过程。例如,

将添加多少个整数? 5

INCLUDE Irvine32.inc
 array_size = 10
 .data
 prompt1 byte "How many integers will be added?", 0
 prompt2 byte "Enter a signed integer: ", 0
 prompt3 byte "The sum of the integers is: ", 0
 array dword array_size dup(?)
 .code
 main proc
        call clrscr
        mov ecx,eax
        call promptMes
        call arraysum
        call displaysum
        exit
main endp
promptMes proc uses ecx edx esi
        mov edx,offset prompt1
        mov esi,offset array
        call writestring        
        call readint            
        call crlf               
        call promptforintegers
        ret
promptMes endp
promptforintegers proc uses ecx edx esi
    mov edx,offset prompt2      
    l1: call writestring        
    call readint            
    call crlf               
    mov [esi], ax               
    add esi,type word       

        loop l1
        ret
promptforintegers endp
arraysum proc uses esi ecx
    mov eax, 0                      
    l1: add eax,[esi]               
    add esi,type dword              
    loop l1         
    ret                         
arraysum endp
    mov edx, offset prompt3         
    call writestring
    call writeint               
    call crlf
    ret
displaysum endp
end main

我的问题是我的计数器继续迭代无限次,我的问题是我如何以及在哪里获取上面的用户输入 (5) 并将计数器和 (5) 传递给过程 promptForIntegers?

我在网上看到same question,这是他们得到的回复。

函数 readint 在哪里?

如何将 ecx 设置为用户想要的整数个数?也许 它在 readint 中设置?

但是,他们没有完整显示代码的来源。而且我不知道如何使用 readint 修改我的代码。谁能告诉我使用 readint 函数会是什么样子?

【问题讨论】:

    标签: arrays assembly masm irvine32


    【解决方案1】:
    INCLUDE Irvine32.inc
    array_size = 10
    .data
    prompt1 byte "How many integers will be added?", 0
    prompt2 byte "Enter a signed integer: ", 0
    prompt3 byte "The sum of the integers is: ", 0
    array dword array_size dup(?)
    .code
    main proc
        call clrscr
        mov ecx,eax
        call promptMes
        call arraysum
        call displaysum
        exit
    main endp
    promptMes proc uses ecx edx esi
        mov edx,offset prompt1
        mov esi,offset array
        call writestring        
        call readint            
        call crlf               
        call promptforintegers
        ret
    promptMes endp
    promptforintegers proc uses ecx edx esi
    mov edx,offset prompt2      
    l1: call writestring        
    call readint            
    call crlf               
    mov [esi], ax               
    add esi,type word       
    
        loop l1
        ret
    promptforintegers endp
    arraysum proc uses esi ecx
    mov eax, 0                      
    l1: add eax,[esi]               
    add esi,type dword              
    loop l1         
    ret                         
    arraysum endp
    mov edx, offset prompt3         
    call writestring
    call writeint               
    call crlf
    ret
    displaysum endp
    end main
    

    【讨论】:

    • 虽然这些代码可以解决问题,但最好能提供代码如何解决问题的说明。
    猜你喜欢
    • 2011-03-13
    • 2010-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-12
    • 2011-06-21
    • 2015-05-09
    • 1970-01-01
    相关资源
    最近更新 更多