问题 多项选择题

请编制程序ex12.ASM,其功能是:内存中连续存放着30个无符号字节数,求它们的和。和值形式按字存放,此前按顺序存放参加运算的30个字节。
例如:
内存中有01H,02H,03H,……
结果为01H,02H,03H,……(30个参加运算的字节),后跟一个字(为前面各30个字节的和)。
部分程序已给出,其中原始数据由过程LOAD从文件INPUT1.DAT中读入SOURCE开始的内存单元中,运算的结果要求从RESULT开始存放,由过程SAVE保存到文件OUTPUT1.DAT中。补充BEGIN和END之间已给出的源程序使其完整(空白已用横线标出,每行空白一般只需一条指令,但采用功能相当的多条指令亦可),或删除BEGIN和END之间原有的代码并自行编程来完成要求的功能。
对程序进行汇编,并与IO.OBJ链接产生执行文件,最终运行程序产生结果。调试中发现整个程序中存在错误之处,请加以修改。
[试题程序]
EXTRN LOAD:FAR,SAVE:FAR
N EQU 30
STAC SEGMENT STACK
DB 128 DUP()
STAC ENDS
DATA SEGMENT
SOURCE DB N DUP()
RESULT DB N+2DUP(0)
NAME0 DB ’INPUT1.DAT’,0
NAME1 DB ’OUTPUT1.DAT’,0
DATA ENDS
CODE SEGMENT

ASSUME CS:CODE,DS:DATA,SS:STAC
START
PROC
FAR
PUSH
DS
XOR
AX,AX
PUSH
AX
MOV
AX,DATA
MOV DS,AX
LEA DX,SOURCE
;数据区起始地址
LEA
SI,NAME0
;原始数据文件名
MOV
CX,N
;字节数
CALL LOAD
;从’INPUT1.DAT’中读取数据
; **** BEGIN ****
LEA
SI,SOURCE
LEA DI,RESULT
MOV
CX,N
MOV
BX,0
NEXT:
MOV
AL,[SI]
(1)
(2)
MOV
[DI], (3)
(4)
(5)
LOOP
NEXT
MOV
[DI], (6)
; ****END****
LEA DX,RESULT
;结果数据区首址
LEA
SI,NAMEI
;结果文件名
MOV
CX,N+2
;结果字节数
CALL
SAVE
;保存结果到文件
RET
START
ENDP
CODE
ENDS
END
START

答案

参考答案:; **** BEGIN ****
LEA SI,SOURCE
LEA DI,RESULT
MOV CX,N
MOV BX,0
NEXT:MOV AL,[SI]
MOV AH,0
ADD BX,AX
MOV [DI],AL
INC SI
INC DI
LOOP NEXT
MOV [DI],BX
; ****END****

解析: 本题主要考查简单的求和问题。考生需要注意内存中连续存放着30个无符号字节数,求它们的和。和值形式按字存放,此前按顺序存放参加运算的30字节。本题难点在于用循环指令求和,MOV AH,0用来设置初值,INC DI用来移动地址让上一个数的所得结果和下一个数相加,直到循环结束。

单项选择题
单项选择题

My Views on Gambling
Most of life is a gamble. Very many of the things we do involve taking some risk in order to achieve a satisfactory result. We undertake a new job with no idea of the more indirect consequences of our action. Marriage is certainly a gamble and so is the bringing into existence of children, who could prove sad liabilities. A journey, a business transaction, even a chance remark may result immediately or ultimately in tragedy. Perpetually we gamble-against life, destiny, chance, the unknown, call the invisible opponent what we will. Human survival and progress indicate that usually we win.
So the gambling instinct must be an elemental one. Taking risks to achieve something is a characteristic of all forms of life, including humanity. As soon as man acquired property, the challenge he habitually issued to destiny found an additional expression in a human contest. Early may well have staked his flint axe, his bearskin, his wife, in the hope of adding to his possessions. The acquirement of desirable but nonessential commodities must have increased his scope enormously, while the risk of complete disaster lessened.
So long as man was gambling against destiny, the odds were usually in his favor, especially when he used commonsense. But as the methods of gambling multiplied, the chances of success decreased. A wager against one person offered on average even chances and no third party profited by the transaction. But as soon as commercialized city life developed, mass gambling become common. Thousands of people now compete for large prizes, but with only minute chances of success, while the organizers of gambling concerns enjoy big profits with, in some cases, no risk at all. Few clients of the betting shops, football pools, state lotteries, bingo sessions, even charity raffles, realize fully the flimsiness of their chances and the fact that without fantastic luck they are certain to lose rather than gain.
Little irreparable harm results for the normal individual. That big business profits from the satisfaction of a human instinct is a common enough phenomenon. The average wage-earner, who leads a colorless existence, devotes a small percentage of his earnings to keeping alive with extraordinary constancy the dream of achieving some magic change in his life. Gambling is in most cases a non-toxic drug against boredom and apathy and may well preserve good temper, patience and optimism in dreary circumstances. A sudden windfall may unbalance a weaker, less intelligent person and even ruin his life. And the line of something for nothing as an ideal evokes criticism from the more rigidly upright representatives of the community. But few of us have the right to condemn as few of us can say we never gamble-even it is only investing a few pence a week in the firm’s football sweep or the church bazaar "lucky dip."
Trouble develops, however, when any human instinct or appetite becomes overdeveloped. Moderate drinking produces few harmful effects but drunkenness and alcoholism can have terrible consequences. With an unlucky combination of temperament and circumstances, gambling can only become an obsession, almost a form of insanity, resulting in the loss not only of a man’s property but of his self-respect and his conscience. Far worse are the sufferings of his dependants, deprived of material comfort and condemned to watching his deterioration and hopelessness. They share none of his feverish excitement or the exhilaration of his rare success. The fact that he does not wish to be cured makes psychological treatment of the gambling addict almost impossible. He will use any means, including stealing, to enable him to carry on. It might be possible to pay what salary he can earn to his wife for the family maintenance but this is clearly no solution. Nothing-education, home environment, other interest, wise discouragement-is likely to restrain the obsessed gambler and even when it is he alone who suffers the consequences, his disease is a cruel one, resulting in a wasted, unhappy life.
Even in the case of the more physically harmful of human indulgences, repressive legislation often merely increases the damage by causing more vicious activities designed to perpetuate the indulgence in secret. On the whole, though negative, gambling is no vice within reasonable limits. It would still exist in an ideal society. The most we can hope for is control over exaggerated profits resulting from its business exploitation, far more attention and research devoted to the unhappy gambling addict and the type of education which will encourage an interest in so many other constructive activities that gambling itself will lose its fascination as an opiate to a dreary existence. It could be regarded as an occasional mildly exciting game, never to be taken very seriously.

According to the author, we gamble regardless of the risk because we

A.want to survive.

B.usually win in the gamble.

C.don’t know the indirect consequences of the action.

D.wish to achieve what may bring us satisfaction.