3. Разработка программы.
Разработаем программу
3.1. Написание кода
Для создания файла воспользуемся командой echo:

CMD>> echo pract3 > pract3.asm
Теперь в созданном файле (F4) впишем код
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
4
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, 10 |
|
MUL DX |
; Multiply the multiplier (AX) by 10 |
MOV SI, AX |
; Move the multiplier (AX) back to SI |
LOOP MET |
; Move to the previous character |
|
|
MOV CX, DI
;========================== 2 ===================================
MOV SI, DI; SI holds the double
LEA DI, BUF2+128
TOBASE2:
CMP SI, 0
JE OUT2
SHR SI, 1
JC CARRYSET2
MOV [DI], '0'
DEC DI
CALL TOBASE2
CARRYSET2:
MOV [DI], '1'
DEC DI
CALL TOBASE2
OUT2:
CALL PRINTLN ; Next line
LEA DX, STR2
CALL OUTPUT
5
INC DI |
; Returning the extra subtraction |
LEA DX, DI |
|
CALL OUTPUT |
|
|
|
;========================== 8 ===================================
MOV SI, CX
LEA DI, BUF8+128
TOBASE8:
MOV BX, '0'
MOV AX, SI
AND AX, 7
ADD BX, AX ; now the digit is in DX
MOV [DI], BL
DEC DI
SHR SI, 3
CMP SI, 0
JE OUT8
CALL TOBASE8
OUT8:
CALL PRINTLN
LEA DX, STR3
CALL OUTPUT
INC DI
LEA DX, DI
CALL OUTPUT
;========================== 16 ===================================
MOV SI, CX
LEA DI, BUF8+128
TOBASE16:
6
MOV BX, '0'
MOV AX, SI
AND AX, 15
CMP AX, 9
JG ISLETTER
ADD BX, AX ; now the digit is in DX MOV [DI], BL
DEC DI
SHR SI, 4
CMP SI, 0
JE OUT16
CALL TOBASE16
OUT16:
CALL PRINTLN
LEA DX, STR4
CALL OUTPUT
INC DI
LEA DX, DI
CALL OUTPUT
EXIT:
MOV AH, 4CH
INT 21H
OUTPUT:
MOV AH, 09H
INT 21H
RET
PRINTLN:
MOV AH, 02H
MOV DL, 10
INT 21h
7
