4. Выводы
В ходе работы научились вводить в ассемблерную программу числовую информацию.
Разработали алгоритмы для перевода чисел в различные системы счисления.
5. Зачетное задание
CODE SEGMENT
ASSUME CS:CODE, DS:CODE, SS:CODE
ORG 100h
START:
LEA DX, STR1
CALL OUTPUT
; Input a number in the form of a string
MOV AH, |
0AH |
; |
Function number in AH |
LEA DX, BUF |
; |
DS:DX address of the input buffer |
INT 21H |
|
; Interrupt 21H for input |
; Convert the string to a number, result in DI |
MOV DI, |
0 |
|
|
LEA BX, |
BUF+1 |
; BX points to the second element of the buffer |
MOV CX, |
[BX] |
; CX holds the count of entered characters |
XOR CH, |
CH |
|
|
MOV SI, |
1 |
; SI holds the multiplier |
MET: |
|
|
|
PUSH SI |
; Save SI (multiplier) in the stack |
MOV SI, CX |
; SI holds the current character number |
MOV AX, [BX+SI] ; AX holds the current character |
XOR AH, AH |
|
|
POP SI |
; Retrieve the multiplier (SI) from the stack |
SUB AX, 30H |
; Convert the character (AX) to a digit |
MUL SI |
; Multiply the digit (AX) by the multiplier (SI) |
ADD DI, AX |
; Add to the resulting number |
MOV AX, SI |
; Move the multiplier (AX) to SI |
MOV DX, 8 |
; Now we should multiply by 8 because of base of system |
MUL DX |
; Multiply the multiplier (AX) by 8 |
MOV SI, AX |
; Move the multiplier (AX) back to SI |
LOOP MET |
; Move to the previous character |
MOV CX, DI |
|
|
|
|
|
|
MOV AX, DI
MOV SI, 128
MOV CX, 10
CONVERT: ; Converting integer to string XOR DX, DX
DIV CX
ADD DX, '0'
MOV [BUF2+SI], DL
CMP AX, 0
JE OUT10
DEC SI
CALL CONVERT
OUT10: ; Output
CALL NEXTLINE
LEA DX, STR2
CALL OUTPUT
LEA DX, [BUF2+SI]
CALL OUTPUT
EXIT:
MOV AH, 4CH
INT 21H
OUTPUT:
MOV AH, 09H
INT 21H
RET
NEXTLINE:
MOV AH, 02H
MOV DL, 10
INT 21h
RET
STR1 DB 'OCT: $'
STR2 DB 'DEC: $'
BUF DB 128, 0, 128 DUP('$')
BUF2 DB 128, 0, 128 DUP('$')
CODE ENDS
END START
Рис. 5.1
Рис. 5.2