如何制作我的汇编代码WOrk

时间:2015-02-04 03:48:03

标签: assembly dos x86-16

我正在使用汇编语言创建菜单。操作工作,但CMP和跳转命令不。但我不能让它工作..任何建议我是大会新的,只是试验它..请帮帮我

#make_COM#

; COM file is loaded at CS:0100h
ORG 100h

jmp start

msg9 db "Enter 1: Addition "
     db 10,13, "Enter 2: Subtraction "
     db 10,13, "Enter 3: Multiplication: $" 


num9 db 0


start:

mov ax, 3
int 10h

lea dx, msg9
mov ah, 9
int 21h

mov ah, 1
int 21h
sub al,30h
mov num9,al

mov bl,al
cmp bl,4

jl addition
je subtraction
jg multiplication


;--------------------------------------------------------------------------------------------

multiplication:

msg1 db "Enter 1st number:  $"
msg2 db 10,13, "Enter 2nd number:  $"
msg3 db 10,13, "SUM: $"

num1 db 0
num2 db 0
num3 db 0
num4 db 0



mov ax, 3
int 10h

lea dx, msg1
mov ah, 9
int 21h

mov ah, 1
int 21h
sub al,30h
mov num1,al


lea dx, msg2
mov ah, 9
int 21h

mov ah, 1
int 21h
sub al,30h
mov num2,al


lea dx, msg3
mov ah, 9
int 21h


mov al,num1
mov bl,num2
mul bl

mov bl,al
cmp bl,9

jl less
jl greater


greater:

xor ax,ax
mov al,bl
mov bl,10
div bl

mov bl,ah

mov dl,al
or dl,30h
mov ah,2
int 21h

mov dl,bl
or dl,30h
mov ah,2
int 21h


less:

mov dl,al
or dl,30h
mov ah,2
int 21h

int 20h


;-----------------------------------------------------------------

addition:

msg4 db "Enter 1st number: $"
msg5 db 10,13, " Enter 2nd number $"
msg6 db 10,13, " Sum: $"

num5 db 0
num6 db 0
num7 db 0
num8 db 0

mov ax,3
int 10h 

lea dx, msg4
mov ah, 9
int 21h 

mov ah,1
int 21h
sub al,30h 
mov num5,al  

mov ah,1
int 21h
sub al,30h 
mov num6,al  

lea dx, msg5
mov ah, 9
int 21h

mov ah,1
int 21h
sub al,30h
mov num7,al

mov ah,1
int 21h
sub al,30h
mov num8,al


lea dx, msg6
mov ah, 9
int 21h

mov al,num1
add al,num3

mov bl,num2 
add bl,num4 

mov dl,al
or dl,30h
mov ah,30h
mov ah,2 
int 21h

mov dl,bl
or dl,30h
mov ah,30h
mov ah,2 
int 21h

;----------------------------------------------------------------------------------------------


subtraction:

msg11 db "Enter 1st number: $"
msg12 db 10,13, "$"
msg13 db 10,13, "Enter 2nd number: $"
msg14 db 10,13, "Difference : $"

num15 db 0
num16 db 0
num17 db 0
num18 db 0

mov ax,3
int 10h 

lea dx, msg11
mov ah, 9
int 21h 

mov ah,1
int 21h
sub al,30h 
mov num15,al 

mov ah,1
int 21h
sub al,30h 
mov num16,al 

lea dx, msg14
mov ah, 9
int 21h 

lea dx, msg12
mov ah, 9
int 21h

mov ah,1
int 21h
sub al,30h
mov num17,al

mov ah,1
int 21h
sub al,30h 
mov num18,al 

lea dx, msg14
mov ah, 9
int 21h


mov al,num15,num16
mov bl,num17,num18
cmp al,bl


JG positive
JL negative



positive:

mov al,num15
sub al,num17

mov bl,num16
sub bl,num18

mov dl,al
or dl,30h
mov ah,30h
mov ah,2 
int 21h

mov dl,bl
or dl,30h
mov ah,30h
mov ah,2 
int 21h

int 20h

negative:

mov dl,'-'
mov ah,2
int 21h

mov al,num15
sub al,num17

mov bl,num16
sub bl,num18

mov dl,al
or dl,30h
mov ah,30h
mov ah,2 
int 21h


mov dl,bl
or dl,30h
mov ah,30h
mov ah,2 
int 21h

lea dx, msg14
mov ah, 9
int 21h

int 20h

2 个答案:

答案 0 :(得分:1)

由于您的菜单使用1,2和3,您需要与2进行比较。

cmp bl,4
jl addition
je subtraction
jg multiplication

您需要跳过这些 msg _ num _ 行。 (msg3应为 PRODUCT

multiplication:
jmp multiplication_bis
msg1 db "Enter 1st number:  $"
...
multiplication_bis:

将1位数字与2位数字分开,与10相比。

cmp bl,10
jl less
jl greater  ; <-- useless, the code can fall through

less 块不得落入 less 块中。

int 20h  ; <-- add this one
less:

您需要跳过这些 msg _ num _ 行。

addition:
jmp addition_bis
msg4 db "Enter 1st number:  $"
...
addition_bis:

您使用了错误的数据。我怀疑你甚至想使用2位数输入。现在您只需添加单独的1位数输入。

mov al,num1  ; should be num5
add al,num3  ; should be num7
mov bl,num2  ; should be num6
add bl,num4  ; should be num8

您需要跳过这些 msg _ num _ 行。

int 20h  ; You forgot to cut off the *addition* block
subtraction:
jmp subtraction_bis
msg11 db "Enter 1st number:  $"
...
subtraction_bis:

选择了错误的消息。

lea dx, msg14  ; should be msg13
mov ah, 9
int 21h 
lea dx, msg12  ; is useless!
mov ah, 9
int 21h

在X86程序集中不存在。

mov al,num15,num16  ; loose ,num16
mov bl,num17,num18  ; loose ,num18
cmp al,bl
JG positive
JL negative

您需要交换操作数才能获得有意义的结果。

negative:
mov dl,'-'
mov ah,2
int 21h
mov al,num15  ; should be num17
sub al,num17  ; should be num15
mov bl,num16  ; should be num18
sub bl,num18  ; should be num16

程序以 msg14 的多余显示结束。无意?

答案 1 :(得分:0)

您的加法,减法和乘法部分都以一个小数据块开头,但是分支到它们的代码分支到数据块的开头,然后尝试执行它在那里找到的文本。将数据块与代码分开,并将标签放在代码中的适当位置。

;Your instruction `jl addition` branches to here:

addition:

msg4 db "Enter 1st number: $"
msg5 db 10,13, " Enter 2nd number $"
msg6 db 10,13, " Sum: $"

num5 db 0
num6 db 0
num7 db 0
num8 db 0

; It should branch to here

mov ax,3
int 10h