可以运行装配程序

发布于 2025-02-07 21:38:35 字数 2576 浏览 2 评论 0原文

因此,该项目基本上是关于可以使用4个基本操作的计算器进行编码:加法,减法,乘法和划分,以汇编语言。很抱歉,这些评论是用法语编写的,我想您无论如何都不需要它们理解代码。

可能会有所帮助:我的老师说我报告了一个不属于其放置位置的堆栈部分。 当我运行代码时,我会得到以下错误:

(56) error A2006: undefined symbol : scan_num
(89) error A2006: undefined symbol : scan_num
(100)error A2006: undefined symbol : do_plus
(103)error A2006: undefined symbol : do_minus
(106) error A2006: undefined symbol : do_mult
(109) error A2006: undefined symbol : do_div
(128) error A2006: undefined symbol : main

这是我的代码:

SSEG  SEGMENT      STACK
      DB          32 DUP("STACK---")
SSEG  ENDS
;===========================================================code segment
            assume cs:cseg, ds:cseg, es:cseg
cseg        segment

            org 100h
;----------

name "CALCULATRICE"

PUTC    MACRO char
        PUSH AX
        MOV AL,char
        MOV AH, 0Eh
        INT 10h
        POP AX
ENDM

jmp start

;------------- Zone de donnée

msg0    db "BELLAL MOHAMED BUT1 2021/2022",0Dh,0Ah
        db "CALCULATOR3000 gerant les quatres opérations basiques ( + - * / )",0Dh,0Ah,"$"
msg1    db 0Dh,0Ah,0Dh,0Ah, "Entrer le premier terme de l'opération: $"
msg2    db "Choisissez l'opérateur à utiliser: + - * / : $"
msg3    db "Entrer le second terme de l'opération: $"
msg4    db 0Dh, 0Ah,"Le résultat est: $"
msg5    db 0Dh, 0Ah," ",0Dh,0Ah,"$"
err1    db "Saisie incorrecte",0Dh,0Ah,"$"
smth    db "Et .... $"

opr db "?" ; variable contenant l'opérateur

num1 dw ? ; variable contenant le premier terme de l'opération
num2 dw ? ; variable contenant le deuxième terme de l'opération

;--------------- PROGRAMME

start:
mov dx, offset msg0
mov ah, 9
int 21h

lea dx, msg1
mov ah, 09h     ; afficher le premier message
int 21h

; récupérer un nombre saisi par l'utilisateur et on le stock dans
; le registre CX

call scan_num

mov num1, cx ; stocker le nombre dans num1

; nouvelle ligne
putc 0Dh
putc 0Ah

lea dx, msg2
mov ah, 09h         ; affiche le deuxième message
int 21h

; récupérer l'opérateur
mov ah, 1
int 21h
mov opr, al

; nouvelle ligne
putc 0Dh
putc 0Ah

cmp opr, "q"        ; q pour quitter
je exit

cmp opr, "*"
jb wrong_opr
cmp opr, "/"
ja wrong_opr

lea dx, msg3
mov ah, 09h
int 21h

call scan_num

mov num2, cx

lea dx, msg4
mov ah, 09h
int 21h

;------------- CALCULER

cmp opr, "+"
je do_plus

cmp opr, "-"
je do_minus

cmp opr, "*"
je do_mult

cmp opr, "/"
je do_div

;---------- CAS PAR DEFAUT

wrong_opr:
lea dx, err1
mov ah, 09h
int 21h

exit:

lea dx, msg5
mov ah, 09h
int 21h

mov ah, 0

;---------
cseg        ends
            end main

So the project is basically about coding a calculator that can use the 4 basic operations: addition, subtraction, multiplication, and division, in assembly language. I'm sorry but the comments are written in French I guess you won't need them to understand the code anyway.

May help: My teacher said that I reported a stack segment that doesn't belong to where it is placed.
When I run the code I get these errors :

(56) error A2006: undefined symbol : scan_num
(89) error A2006: undefined symbol : scan_num
(100)error A2006: undefined symbol : do_plus
(103)error A2006: undefined symbol : do_minus
(106) error A2006: undefined symbol : do_mult
(109) error A2006: undefined symbol : do_div
(128) error A2006: undefined symbol : main

Here is my code:

SSEG  SEGMENT      STACK
      DB          32 DUP("STACK---")
SSEG  ENDS
;===========================================================code segment
            assume cs:cseg, ds:cseg, es:cseg
cseg        segment

            org 100h
;----------

name "CALCULATRICE"

PUTC    MACRO char
        PUSH AX
        MOV AL,char
        MOV AH, 0Eh
        INT 10h
        POP AX
ENDM

jmp start

;------------- Zone de donnée

msg0    db "BELLAL MOHAMED BUT1 2021/2022",0Dh,0Ah
        db "CALCULATOR3000 gerant les quatres opérations basiques ( + - * / )",0Dh,0Ah,"
quot;
msg1    db 0Dh,0Ah,0Dh,0Ah, "Entrer le premier terme de l'opération: 
quot;
msg2    db "Choisissez l'opérateur à utiliser: + - * / : 
quot;
msg3    db "Entrer le second terme de l'opération: 
quot;
msg4    db 0Dh, 0Ah,"Le résultat est: 
quot;
msg5    db 0Dh, 0Ah," ",0Dh,0Ah,"
quot;
err1    db "Saisie incorrecte",0Dh,0Ah,"
quot;
smth    db "Et .... 
quot;

opr db "?" ; variable contenant l'opérateur

num1 dw ? ; variable contenant le premier terme de l'opération
num2 dw ? ; variable contenant le deuxième terme de l'opération

;--------------- PROGRAMME

start:
mov dx, offset msg0
mov ah, 9
int 21h

lea dx, msg1
mov ah, 09h     ; afficher le premier message
int 21h

; récupérer un nombre saisi par l'utilisateur et on le stock dans
; le registre CX

call scan_num

mov num1, cx ; stocker le nombre dans num1

; nouvelle ligne
putc 0Dh
putc 0Ah

lea dx, msg2
mov ah, 09h         ; affiche le deuxième message
int 21h

; récupérer l'opérateur
mov ah, 1
int 21h
mov opr, al

; nouvelle ligne
putc 0Dh
putc 0Ah

cmp opr, "q"        ; q pour quitter
je exit

cmp opr, "*"
jb wrong_opr
cmp opr, "/"
ja wrong_opr

lea dx, msg3
mov ah, 09h
int 21h

call scan_num

mov num2, cx

lea dx, msg4
mov ah, 09h
int 21h

;------------- CALCULER

cmp opr, "+"
je do_plus

cmp opr, "-"
je do_minus

cmp opr, "*"
je do_mult

cmp opr, "/"
je do_div

;---------- CAS PAR DEFAUT

wrong_opr:
lea dx, err1
mov ah, 09h
int 21h

exit:

lea dx, msg5
mov ah, 09h
int 21h

mov ah, 0

;---------
cseg        ends
            end main

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

來不及說愛妳 2025-02-14 21:38:35

如果您使用代码标签作为指令操作数,则它也需要在您的代码中与结肠在其线路上的某个地方存在,或者如果您的汇编程序允许,则它也需要与colon一起使用。

您可能已经注意到,您没有看到forgation_opr的类似错误消息。那是因为您在源代码中具有该标签。

cmp opr, "*"
jb wrong_opr
cmp opr, "/"
ja wrong_opr

; rest of your code

wrong_opr:    ;the 'jb' and 'ja' statements will take you here.

您会收到其他标签的错误消息,因为它们不在您的程序中。

这是我现在修复它的方法:

;--------------- PROGRAMME

start:
main:          ;add this here to "balance" your "end main"
mov dx, offset msg0
mov ah, 9
int 21h

然后您可以执行以下操作。我故意以次优的方式编写了这篇文章,以使其更容易阅读。

cmp opr, "+"
je do_plus

cmp opr, "-"
je do_minus

cmp opr, "*"
je do_mult

cmp opr, "/"
je do_div
jmp wrong_opr   ;if none of the above, goto default



do_plus:
; your code for what happens when user types + goes here
jmp exit

do_minus:
; your code for what happens when user types - goes here
jmp exit

do_mult:
; your code for what happens when user types * goes here
jmp exit

do_div:
; your code for what happens when user types / goes here
jmp exit



;---------- CAS PAR DEFAUT

wrong_opr:
lea dx, err1
mov ah, 09h
int 21h

exit:

lea dx, msg5
mov ah, 09h
int 21h

; you need to put the exit code here or your computer will crash.
mov ax,4c00h
int 21h

;down here you can safely put any functions you wish
scan_num:
;you can put your code here for how you scan the user input

ret

;---------
end main   ;I'm not sure but I think these should be in this order.
cseg        ends

那应该足以使这些错误消失。当然,您仍然必须弄清楚如何完成任务。

If you use a code label as an instruction operand, it needs to also exist somewhere in your code on its own line with a colon after it, or a proc statement if your assembler allows it.

You may have noticed that you didn't see a similar error message for wrong_opr. That's because you have that label in your source code.

cmp opr, "*"
jb wrong_opr
cmp opr, "/"
ja wrong_opr

; rest of your code

wrong_opr:    ;the 'jb' and 'ja' statements will take you here.

You got the error messages for the other labels because they're not in your program.

Here's how I'd fix it for now:

;--------------- PROGRAMME

start:
main:          ;add this here to "balance" your "end main"
mov dx, offset msg0
mov ah, 9
int 21h

And then you can do the following. I purposely wrote this in a sub-optimal manner to make it easier to read.

cmp opr, "+"
je do_plus

cmp opr, "-"
je do_minus

cmp opr, "*"
je do_mult

cmp opr, "/"
je do_div
jmp wrong_opr   ;if none of the above, goto default



do_plus:
; your code for what happens when user types + goes here
jmp exit

do_minus:
; your code for what happens when user types - goes here
jmp exit

do_mult:
; your code for what happens when user types * goes here
jmp exit

do_div:
; your code for what happens when user types / goes here
jmp exit



;---------- CAS PAR DEFAUT

wrong_opr:
lea dx, err1
mov ah, 09h
int 21h

exit:

lea dx, msg5
mov ah, 09h
int 21h

; you need to put the exit code here or your computer will crash.
mov ax,4c00h
int 21h

;down here you can safely put any functions you wish
scan_num:
;you can put your code here for how you scan the user input

ret

;---------
end main   ;I'm not sure but I think these should be in this order.
cseg        ends

That should be enough to get those errors to go away. Of course, you'll still have to figure out how you want to accomplish the task.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文