简体   繁体   English

如何使用汇编语言编写此程序

[英]How can I write this program using assembly language

1-Write programs to test that a character read from the keyboard and transfer control to label ok_here, if the character is: 1-编写程序来测试从键盘读取的字符并将控制转移到标签 ok_here,如果字符是:

(i) a valid lowercase letter ( 'a' <= character <= 'z' ) (i) 一个有效的小写字母( 'a' <= character <= 'z' )

(ii) either an uppercase or lowercase letter ('A' <= character <= 'Z' OR 'a' <= character <= 'z') (ii) 大写或小写字母('A' <= 字符 <= 'Z' 或 'a' <= 字符 <= 'z')

(iii) is not a lowercase letter, ie character < 'a' or character > 'z'. (iii) 不是小写字母,即字符 < 'a' 或字符 > 'z'。 The programs should display appropriate messages to prompt for input and indicate whether the character satisfied the relevant test.程序应显示适当的消息以提示输入并指示字符是否满足相关测试。

i)一)

.Model  small

.stack 100h

.code 

Main proc

Mov ah,1h

Int 21h

Cmp AL,'a'

JE then

Tmp else

Then:ok_here

JMP End if

Else mov  AH,4CH

Int 21h

End if

ii) ii)

mov AH,1h

int 21h

cmp Al,'a'

JE  then

Cmp AL,'A'

JE  then

Cmp AL,'z'

JE  then

JMP else

Then ok_here

Jmp End if

Else mov AH,4CH

Int 21h

End if

2-Write a program that reads an uppercase letter, converts it to lowercase and displays the lowercase equivalent. 2-编写一个程序,读取大写字母,将其转换为小写字母并显示小写字母。 the program let the user repeat this process as often as desired.该程序允许用户根据需要经常重复此过程。 The user is asked to enter 'y' to carry out the operation, after each iteration.每次迭代后,要求用户输入“y”以执行操作。

.model small

.stack 100h

.data

CR  EQU 0DH

LF EQU 0AH

MSG1 DB 'enter an uppercase letter'

MSG2 DB CRLF ' the lowercase equivalent'

CHAR DB ?

.code

Main proc

Mov AX @data

Mov DS,AX

LEA DX,MSG1

Mov AH,@H

Int 21h

SAR AL.20h

Mov CHAR,AL

LGA DX ,MSG2

Mov AH,02H

Int 21h

Mov AH,4CH

Int 21h

Main Endp

End main

Is my code correct?我的代码正确吗?

No.没有。

Your first program only tests whether AL is lowercase 'a' or not.你的第一个程序只测试 AL 是否是小写的“a”。 It has also a syntax error, because you are using ok_here as an instruction, not a label (the label would be Then ).它还有一个语法错误,因为您使用 ok_here 作为指令,而不是标签(标签将是Then )。 Besides, I guess that the Tmp instruction is actually the JMP instruction.另外,我猜Tmp指令实际上是JMP指令。

For your first program to be correct, you must test if the value in AL is equal or greater than 'a' AND is equal or less than 'z':要使您的第一个程序正确,您必须测试 AL 中的值是否等于或大于“a”且等于或小于“z”:

CMP AL,'a'
JB notok
CMP AL,'z'
JA notok
ok_here: ;if we reach this point, AL is a lowercase letter

Your second program does a similar thing: only goes to ok_here if AL is 'A', 'a' or 'z'.你的第二个程序做了类似的事情:只有当 AL 是 'A'、'a' 或 'z' 时才转到 ok_here。 You only use the JE instruction, which jumps if AL is equal to the second operand of the CMP instruction.您只使用 JE 指令,如果 AL 等于 CMP 指令的第二个操作数,则该指令会跳转。 To fix it, use the previous code to test if AL is lowercase, and if it is so, repeat the test but this time with 'A' and 'Z'.要修复它,请使用前面的代码测试 AL 是否为小写,如果是,则重复测试,但这次使用 'A' 和 'Z'。 That is: four CMP's and four conditional jumps.即:四个 CMP 和四个条件跳转。

Also, your program lacks the strings to tell the user to input a character and the printed messages telling if the character meets the criteria or not.此外,您的程序缺少告诉用户输入字符的字符串和告知字符是否符合条件的打印消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM