| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 884 人关注过本帖
标题:[求助]课程设计
只看楼主 加入收藏
kill444
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2005-9-6
收藏
 问题点数:0 回复次数:5 
[求助]课程设计

利用系统功能调用从键盘输入10个2位十进制无符号数(0-99),求出最大数和最小数,利用系统功能调用将此最大数和最小数如以下格式:
MAX **
MIN **
输出。
(用汇编语言写出程序)

搜索更多相关主题的帖子: 课程 设计 
2006-05-22 13:11
公子吕
Rank: 1
等 级:新手上路
帖 子:79
专家分:0
注 册:2006-5-4
收藏
得分:0 

根据题意可分为3个基本部分:
1,键盘接收输入;
2,比较大小;
3,按格式输出;

既然是课程设计,那汇编你该学了一遍了,你说说你会什么不会什么吧。
段定义?
基本指令?
21中断调用?

如果什么都不会就好好看看书吧,如果会一点就把你会的代码部分写出来,我再来帮你。

2006-05-22 14:39
kill444
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2005-9-6
收藏
得分:0 
键盘接收输入和按格式输出不会!!!(说真的,我的汇编学的一点都不好,望大哥多点指教。谢谢!)
DATA SEGMENT
MAX Db ?
MIN Db ?
BLOCK DB FFH,F3H,3FH,78H,A3H,32H,11H,FH,23H,18H ;这是初始,如果调用键盘输入该怎么写?
COUNT EQU $-BLOCK
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START: MOV BX,OFFSET BLOCK
MOV AL,[BX]
MOV AH,[BX]
INC BX
MOV CX,COUNT-1
AGAIN: CMP AL,[BX]
JAE NEXT1
MOV AL,[BX]
JMP NEXT
NEXT1: CMP AH,[BX]
JBE NEXT
MOV AH,[BX]
NEXT: INC BX
DEC CX
JNZ AGAIN
MOV MAX,AL
MOV MIN,AH ;要按那种格式输出到显示屏上,应怎么样写这一小段程序那?
RET
START ENDS

2006-05-22 16:01
公子吕
Rank: 1
等 级:新手上路
帖 子:79
专家分:0
注 册:2006-5-4
收藏
得分:0 

汇编里从键盘接收的数字如果不是一位数,就得当作字符串接收。那么可以用int21的10号中断接收数字字符串,然后将字符串转换成integer数进行运算。
.data
data_input db 32
db ?
db 30 dup (?)
mov dx,offset data_input
mov ah,10
int 21h
接收的数字可以用逗号隔开,不要用回车。然后调用后面我给出的将字符串转换为integer数的子程序。
调用前将要转换的串地址送bx并压入堆栈。转换的结果保存在ax中。如下:
mov bx,offset data_input+2 ;这是通过10号中断接收的第一个数字串的地址。
push bx
call atoiproc
调用过后将ax内容送存储器保存(在data里开辟一个空间),然后将bx地址增量,继续调用atoiproc
接下来比较存储器里的10个数,找出最大的和最小的,因为要格式化输出,必须将integer数转换成字符串调用09号中断,下面也将给出integer转字符串的子程序。调用前,将要转换的数放ax,转换的结果字符串地址放bx,并将bx,ax先后压入堆栈,如下:
mov bx,offset str_output
push bx
push ax
call itoaproc

在调用9号中断之前,要将转换出来的数字字符串尾部加一个$符号,否则系统无法确定何时结束输出。
子程序代码如下,看得懂最好,看不懂也无所谓。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;io.asm;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;-----------------------------------------------------------------------------

atoiproc proc near
push bp ; save base pointer
mov bp, sp ; establish stack frame
sub sp, 2 ; local space for sign
push bx ; Save registers
push cx
push dx
pushf ; save flags

mov si,[bp+4] ; get parameter (source addr)

WhileBlank: cmp BYTE PTR [si],' ' ; space?
jne EndWhileBlank ; exit if not
inc si ; increment character pointer
jmp WhileBlank ; and try again
EndWhileBlank:

mov ax,1 ; default sign multiplier
IfPlus: cmp BYTE PTR [si],'+' ; leading + ?
je SkipSign ; if so, skip over
IfMinus: cmp BYTE PTR [si],'-' ; leading - ?
jne EndIfSign ; if not, save default +
mov ax,-1 ; -1 for minus sign
SkipSign: inc si ; move past sign
EndIfSign:

mov [bp-1],ax ; save sign multiplier
mov ax,0 ; number being accumulated
mov cx,0 ; count of digits so far

WhileDigit: cmp BYTE PTR [si],'0' ; compare next character to '0'
jl EndWhileDigit ; not a digit if smaller than '0'
cmp BYTE PTR [si],'9' ; compare to '9'
jg EndWhileDigit ; not a digit if bigger than '9'
mov dl,10
imul dl ; multiply old number by 10
jo overflow ; exit if product too large
mov bl,[si] ; ASCII character to BL
and bx,000Fh ; convert to single-digit integer
add ax,bx ; add to sum
jc overflow ; exit if sum too large
inc cx ; increment digit count
inc si ; increment character pointer
jmp WhileDigit ; go try next character
EndWhileDigit:

cmp cx,0 ; no digits?
jz overflow ; if so, set overflow error flag

; if value is 8000h and sign is '-', want to return 8000h (-32,768)

cmp ax,8000h ; 8000h ?
jne TooBig?
cmp WORD PTR [bp-1],-1 ; multiplier -1 ?
je ok1 ; if so, return 8000h

TooBig?: test ax,ax ; check sign flag
jns ok ; will be set if number > 32,767

overflow: pop ax ; get flags
or ax,0000100001000100B ; set overflow, zero & parity flags
and ax,1111111101111110B ; reset sign and carry flags
push ax ; push new flag values
mov ax,0 ; return value of zero
jmp AToIExit ; quit

ok: imul WORD PTR [bp-1] ; make signed number
ok1: popf ; get original flags
test ax,ax ; set flags for new number
pushf ; save flags

AToIExit: popf ; get flags
pop dx ; restore registers
pop cx
pop bx
mov sp, bp ; delete local variable space
pop bp
ret 2 ; exit, removing parameter
atoiproc ENDP

;;------------------------------------------------------------------------
itoaproc proc near
push bp
mov bp,sp
push ax
push bx
push cx
push dx
push di
pushf

mov ax,[bp+6]
mov di,[bp+4]

ifSpecial:
cmp ax,8000h
jne EndIfSpecial
mov BYTE PTR [di],'-'
mov BYTE PTR [di+1],'3'
mov BYTE PTR [di+2],'2'
mov BYTE PTR [di+3],'7'
mov BYTE PTR [di+4],'6'
mov BYTE PTR [di+5],'8'
jmp ExitIToA
EndIfSpecial:

mov dx, ax

mov al,' '
mov cx,5 ; first five
cld ; bytes of
rep stosb ; destination field

mov ax, dx ; copy source number
mov cl,' ' ; default sign (blank for +)
IfNeg: cmp ax,0 ; check sign of number
jge EndIfNeg ; skip if not negative
mov cl,'-' ; sign for negative number
neg ax ; number in AX now >= 0
EndIfNeg:

mov bx,10 ; divisor

WhileMore: mov dx,0 ; extend number to doubleword
div bx ; divide by 10
add dl,30h ; convert remainder to character
mov [di],dl ; put character in string
dec di ; move forward to next position
cmp ax,0 ; check quotient
jnz WhileMore ; continue if quotient not zero

mov [di],cl ; insert blank or "-" for sign

ExitIToA: popf ; restore flags and registers
pop di
pop dx
pop cx
pop bx
pop ax
pop bp
ret 3 ;exit, discarding parameters
itoaproc endp


2006-05-22 17:06
公子吕
Rank: 1
等 级:新手上路
帖 子:79
专家分:0
注 册:2006-5-4
收藏
得分:0 

回头看了一下你的代码,有点问题,入口点start:之后第一件事就是要初始化ds段,如下:
start:
mov ax,data
mov ds,ax
还有最后要有
code ends
刚开始肯定是错误一大片的,要有耐心坚持下去。

2006-05-22 17:13
kill444
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2005-9-6
收藏
得分:0 

谢谢,非常感谢您以及您的鼓励!!Thank you very much!!


2006-05-22 17:31
快速回复:[求助]课程设计
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014264 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved