8086 Assembly Prime Check添加输入

时间:2019-06-21 11:49:40

标签: assembly emu8086

我对汇编编程非常陌生 我发现这段代码可以检测数字是否为质数。我现在想知道如何获取用户输入的NUM值。

我在https://github.com/kingspp/8086-MicroProcessor/blob/master/Prime-Check.asm找到了代码

如果有人向我解释如何使用8086寄存器来获取输入,我将不胜感激。

我看了几遍

;NUM is assigned to the Number to be checked
;AL is used as the default no
;BL is used as Dividing Variable. It is Incremented in each loop
;BH is used to know the number of variables which can divide the Number. BH>02, The number is not prime
;BL is made to run x number of times, where x is the given number.

; Declaration Part
.MODEL SMALL
.DATA

NM1 DB "FirstName LastName$"
NM2 DB "FirstName LastName$"

MSG DB "It is Prime$"
NMSG DB "It is not Prime$"
NUM DB 27H      ;Enter the required no here
.CODE

START:
MOV AX,@DATA
MOV DS,AX

MOV AL,NUM
MOV BL,02H      ; The Dividing starts from 2, Hence BH is compare to 02H
MOV DX,0000H    ; To avoid Divide overflow error
MOV AH,00H      ; To avoid Divide overflow error

;Loop to check for Prime No
L1:DIV BL
CMP AH,00H      ; Remainder is compared with 00H (AH)
JNE NEXT
INC BH          ; BH is incremented if the Number is divisible by current value of BL
NEXT:CMP BH,02H ; If BH > 02H, There is no need to proceed, It is not a Prime
JE FALSE        ; The no is not a Prime No
INC BL          ; Increment BL
MOV AX,0000H    ; To avoid Divide overflow error
MOV DX,0000H    ; To avoid Divide overflow error
MOV AL,NUM      ; Move the Default no to AL
CMP BL,NUM      ; Run the loop until BL matches Number. I.e, Run loop x no of times, where x is the Number given
JNE L1          ; Jump to check again with incremented value of BL

;To display The given no is a Prime No
TRUE:       
LEA DX,NM1
LEA DX,NM2
LEA DX,MSG
MOV AH,09H      ; Used to print a string
INT 21H
JMP EXIT

;To display The given no is not a Prime No
FALSE:     
LEA DX,NM1
LEA DX,NM2
LEA DX,NMSG
MOV AH,09H      ; Used to print a string
INT 21H


EXIT:
MOV AH,4CH
INT 21H
END START

0 个答案:

没有答案