主题:求一汇编程序--从键盘输入一字符串并将其以大写形式显示
yigerengudu
[专家分:200] 发布于 2006-05-08 12:39:00
从键盘输入一字符串并将其以大写形式显示
怎么用汇编完整地实现了.
回复列表 (共6个回复)
沙发
书剑一心 [专家分:330] 发布于 2006-05-08 14:56:00
ata SEGMENT
mes1 DB 'Please input a tring:$'
mes2 DB 'output:$'
buf DB 16
DB ?
DB 16 DUP(?)
data ENDS
stack SEGMENT stack
DB 200 DUP(0)
stack ENDS
code SEGMENT
ASSUME DS:data,SS:stack,CS:code
start:
MOV AX,data
MOV DS,AX
LEA DX,mes1 ;show message
MOV AH,9
INT 21h
LEA DX,buf ;input string
MOV AH,10
INT 21h
MOV CL,[buf+1]
CBW
MOV DI,0
ifda: MOV BL,[buf+DI+2] ;judge A or a
CMP BL,'a'
JB yy1
CMP BL,'z'
JB yy2
CMP BL,'z'
JA yy1
yy1: MOV [buf+DI+2],BL
INC DI
JMP SS11
yy2: SUB BL,32
MOV [buf+DI+2],BL
INC DI
JMP SS11
SS11: LOOP ifda
LEA DX,mes2 ;output answer
MOV AH,9
INT 21h
LEA DX,buf+2
MOV AH,9
INT 21h
MOV AH,4ch
INT 21h
code ENDS
END start
我也只写到这个样子了,错了,那位帮我改改。
板凳
llehotnwod [专家分:330] 发布于 2006-05-09 14:23:00
[code]
1 %define stdin 0
2 %define stdout 1
3 %define stderr 2
4
5 section .data
6 msg1 db 'Input:'
7 len_msg1 equ $-msg1
8 msg2 db 'Output:'
9 len_msg2 equ $-msg2
10
11 section .bss
12 buf resb 4096
13 len_buf equ $-buf
14 length resd 1
15
16 section .text
17 global _start
18 _start:
19 ;;;;;Print Msg
20 push dword len_msg1
21 push dword msg1
22 push dword stdout
23 mov eax, 4 ;;;write
24 push eax
25 int 80h
26 ;;;;;Input
27 push dword len_buf
28 push dword buf
29 push dword stdin
30 push eax
31 mov eax, 3 ;;;read
32 int 80h
33 ;;;;;;if<eax==0>exit
34 test eax, eax
35 jz exit
36 ;;;;;dosomething
37 mov dword[length], eax
38 mov ebx, buf
39 mov esi, eax
40 lop:
41 cmp esi, 0
42 jl break
43 ;;;;;;
44 mov al, byte[ebx+esi]
45 cmp al, 'a'
46 jl next
47 cmp al, 'z'
48 jg next
49 sub al, 'a'
50 add al, 'A'
51 mov byte[ebx+esi],al
52 next:
53 dec esi
54 jmp lop
55 break:
56 ;;;;Output
57 push dword len_msg2
58 push dword msg2
59 push dword stdout
60 push eax
61 mov eax, 4;;
62 int 80h
63 push dword length
64 push dword buf
65 push dword stdout
66 push eax
67 mov eax, 4;;;;;;;;write
68 int 80h
69
70 ;;;;Exit
71 exit:
72 push dword 1
73 push dword 0ah
74 push dword stdout
75 push eax
76 mov eax, 4
77 int 80h
78 push eax
79 mov eax, 1 ;;;;_exit
80 int 80h
[/code]
3 楼
aoeBoy [专家分:50] 发布于 2006-05-10 12:53:00
1楼的。我想请问一下
ata SEGMENT
mes1 DB 'Please input a tring:$'
mes2 DB 'output:$'
buf DB 16
DB ?
DB 16 DUP(?)
data ENDS
上例中,为何要先定义个db 16呢?不明白
4 楼
书剑一心 [专家分:330] 发布于 2006-05-13 11:58:00
我是指输入字符串的长度。
我的想法是定义一个缓冲区接受一我们要改变的字符。16指的是这缓冲区能接收16个字符。
我是照着书上做的,以上的是我的理解不知道有错没有,请指点
5 楼
微炅 [专家分:10] 发布于 2006-05-14 20:14:00
预留16字节的空间存放
我做过这题目
好像不用16个 吧
6 楼
66543 [专家分:200] 发布于 2006-05-20 21:45:00
呵呵,好像跟《汇编语言程序设计》(罗万钧 著)里的第五章的第6个习题差不多的吧,如果我没记错的话。
我来回复