【解決方法】アセンブリ言語の計算機

[ad_1]

ずっと悩んでいるプロジェクトがあります。 プログラムの半分は動作し、残りの半分は動作しませんが、エラーはありません。プロセス A と B は動作しますが、CD と E は動作しません。 誰か助けてくれませんか。 これが私がやろうとしていることです

Performance Requirements

Write a program that will perform as a binary calculator. 
The program should begin by prompting the user for his or her name.
The program should then prompt the user to choose from a set of options for calculations.
These options should include 
1) adding two binary numbers (answer in binary), 
2) subtracting two binary numbers (answer in binary), 
3) writing out a decimal number in its binary form, 
4) convert a character to uppercase, and
5) reverse the case of an alphabetic character 
(if entered character is lowercase, then write out uppercase and vice versa)

The program should prompt the user for the relevant inputs and perform the correct operation.

The program should then display the results as blue text on a white background with the user’s name (For example,  "Dr. Rogers, your sum is 100")

Coding requirements

Create a procedure for each operation.

Bonus – For extra credit, implement the following
Modify your code to display the formatted results in a message box.

Checklist is on the next page.

これが私のコードです:

ASM
INCLUDE Irvine32.inc
BUFMAX = 128
.data
CaseTable  BYTE   'A'
           DWORD   Process_A
           BYTE   'B'
           DWORD   Process_B
           BYTE   'C'
           DWORD   Process_C
           BYTE   'D'
           DWORD   Process_D
           BYTE   'E'
           DWORD   Process_E
    NumberOfEntries = 5
        Nameprompt BYTE "Please enter your name: ", 0
        prompt BYTE "Choose a letter by pressing the corresponding capital letter: ", 0dh, 0ah
           BYTE "A: Add two binary numbers", 0dh, 0ah
           BYTE "B: Subtract two binary numbers", 0dh, 0ah
           BYTE "C: Writing from decimal number to a binary form", 0dh, 0ah
           BYTE "D: Converting a character to capital", 0dh, 0ah
           BYTE "E: Reverse the case of an alphabetic character", 0dh, 0ah, 0
    msgA BYTE "Add two binary numbers: ",0
    msgB BYTE "Subtract two binary numbers: ",0
    msgC BYTE "Writing out a decimal number in its binary form: ", 0
    msgD BYTE "Convert a character to an uppercase: ", 0
    msgE BYTE "Reverse the case of an alphabetic character: ", 0

    prompt1 BYTE "Enter a number: ", 0
    prompt2 BYTE "Enter lowercase letter: ", 0
    prompt3 BYTE "Enter a lowercase or capital letter: ", 0
    promptAdd BYTE ", the binary sum is: ", 0
    promptSub BYTE ", the binary difference is: ", 0
    promptCon BYTE ", the binary number is: ", 0
    promptUp BYTE ", this is the uppercase letter: ", 0
    promptReverse BYTE ", this is the reverse case: ", 0
    buffer BYTE BUFMAX+1 DUP(0)
    bufSize DWORD ?
.code
main PROC
    mov edx, OFFSET Nameprompt
    call WriteString
    mov ecx, BUFMAX
    mov edx, OFFSET buffer
    call ReadString
    mov bufSize,eax
    call Crlf
    mov edx, OFFSET prompt
    call WriteString
    call Crlf
    call ReadChar
    mov  ebx,OFFSET CaseTable
    mov  ecx,NumberOfEntries
L1:
    cmp  al,[ebx]
    jne  L2
    call NEAR PTR [ebx + 1]
    call Crlf
    jmp  L3
L2:
    add  ebx,5
    loop L1
L3:
    exit
main ENDP
Process_A PROC
    mov  edx,OFFSET msgA
    call WriteString
    call Crlf
    call Process_A1
    call Process_A2
    ret
Process_A ENDP
Process_A1 PROC
    mov edx,OFFSET prompt1
    call WriteString
    call ReadInt
    mov ebx, eax
    call WriteBinB
    call Crlf
    mov edx,OFFSET prompt1
    call WriteString
    call ReadInt
    mov ecx, eax
    call WriteBinB
    call Crlf
    ret
Process_A1 ENDP
Process_A2 PROC
    call Crlf
    mov ax, blue + (white * 16)
    call SetTextColor
    mov edx,OFFSET buffer
    call WriteString
    mov edx,OFFSET promptAdd
    call WriteString
    add ebx, ecx
    mov eax, ebx
    call WriteBinB
    call Crlf
    mov eax, white + (black * 16)
    call SetTextColor
    ret
Process_A2 ENDP
Process_B PROC
    mov  edx,OFFSET msgB
    call WriteString
    call Crlf
    call Process_B1
    call Process_B2
    ret
Process_B ENDP
Process_B1 PROC
    mov edx,OFFSET prompt1
    call WriteString
    call ReadInt
    mov ebx, eax
    call WriteBinB
    call Crlf
    mov edx,OFFSET prompt1
    call WriteString
    call ReadInt
    mov ecx, eax
    call WriteBinB
    call Crlf
    ret
Process_B1 ENDP
Process_B2 PROC
    call Crlf
    mov eax, blue + (white * 16)
    call SetTextColor
    mov edx,OFFSET buffer
    call WriteString
    mov edx,OFFSET promptSub
    call WriteString
    sub ebx, ecx
    mov eax, ebx
    call WriteBinB
    call Crlf
    mov eax, red + (black * 16)
    call SetTextColor
    ret
Process_B2 ENDP
Process_C PROC
    mov  edx,OFFSET msgC
    call WriteString
    call Crlf
    mov edx,OFFSET prompt1
    call WriteString
    call ReadInt
    mov ebx, eax
    call Crlf
    mov eax, blue + (white * 16)
    call SetTextColor
    mov edx,OFFSET buffer
    call WriteString
    mov edx,OFFSET promptCon
    call WriteString
    mov eax, ebx
    call WriteBinB
    call Crlf
    mov eax, white + (black * 16)
    call SetTextColor
    ret
Process_C ENDP
Process_D PROC
    mov  edx,OFFSET msgD
    call WriteString
    call Crlf
    mov edx,OFFSET prompt2
    call WriteString
    call ReadChar
    call WriteChar
    and al, 11011111b
    mov bl, al
    call Crlf
    mov eax, blue + (white * 16)
    call SetTextColor
    mov edx,OFFSET buffer
    call WriteString
    mov edx,OFFSET promptUp
    call WriteString
    mov eax, 0
    mov al, bl
    call WriteChar
    call Crlf
    mov eax, white + (black * 16)
    call SetTextColor
    ret
Process_D ENDP
Process_E PROC
    mov  edx,OFFSET msgE
    call WriteString
    call Crlf
    mov edx,OFFSET prompt3
    call WriteString
    call ReadChar
    call WriteChar
L1: cmp al, 01100001b
    jl L2
    and al, 11011111b
    mov bl, al
    jmp L3
L2: or al,  00100000b
    mov bl, al
    jmp L3
L3: call Crlf
    mov eax, blue + (white * 16)
    call SetTextColor
    mov edx,OFFSET buffer
    call WriteString
    mov edx,OFFSET promptReverse
    call WriteString
    mov eax, 0
    mov al, bl
    call WriteChar
    call Crlf
    mov eax, white + (blue * 16)
    call SetTextColor
    ret
Process_E ENDP
END main

解決策 1

誰かがあなたのコードをすべて調べて問題を突き止めようとすると、かなりの時間がかかります。問題をさらに切り分けて、コードのより小さなセクションを投稿することは非常に役立ちます。

また、コード内にコメントがないことに気付きました。これにより、他の人がコードをチェックすることが難しくなります。 コメントの追加は、コードが機能せず、その理由がわからない場合に便利なツールです。場合によっては、コメントを追加することで問題が明確になり、答えが明らかになることがあります。

ほんのいくつかの提案:)

解決策 6

MVI A、05 H
MVI B,04H
MVI C、03 H
Bを追加
Cを追加
スタ80
HLT

[ad_2]

コメント

タイトルとURLをコピーしました