Home > other >  How much the asm file properly connected MASM5 assembly?
How much the asm file properly connected MASM5 assembly?

Time:02-23

I write the master file is a.a sm, start to end to end, file is b.a sm, end to end, why use masm b.a sm cannot generate obj files, how to correctly generate b.o bj? Multiple files connection is to use the link a.o bj + b.o bj command?

Master file a.a sm, son call file b.a sm subroutine BinHexN to hexadecimal number output value of bx register,
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Extrn BinHexN: far

; * * * * * * * * * * * * * * * * * * * *
Parm_seg segment; Define the data segment
The sum dw 175 h
Parm_seg ends

; * * * * * * * * * * * * * * * * * * * *
Stack_seg segment
Dw 100 dup (?)
Tos label word
Stack_seg ends

; * * * * * * * * * * * * * * * * * * * *
Code1 segment; Define code segment

The main proc far; The main part of the program

Assume cs: code1, ds: parm_seg, ss: stack_seg
Start:

Mov ax, stack_seg
Mov ss, ax
Mov sp, offset tos

Push the ds
Sub ax, ax
Push ax


Mov ax, parm_seg; The data segment addr
Mov ds, ax; Into the DS register

; The variable sum value to bx, another file subroutine call BinHexn
Mov bx, sum
Call far PTR BinHexN

Mov dl, ah 0
Mov ah, 2
Int 21 h

Ret
The main endp

; -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Code1 ends

; * * * * * * * * * * * * * * * * * * * *
End the start; End the assembly



Son file b.a sm, with bx passed as a parameter in the main program and subroutine, use a binary number in bx subroutine BinHexN displayed as hexadecimal number,
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Public binihexn

Prognam segment
Cs: assume prognam
BinHexN proc far
Push ax
Push cx
Push dx

Mov ch, 0
Mov cl, 4
Rotate_n:
Rol bx, cl; The left digit to right from left to right to move the contents of BX
Mov al, bl; Will move to al BX moving from left to right to the content of the bl, the bl is assigned to al, to deal with al
And al, 0 fh; Mask off the left four digit shielding al high
The add al, 30 h; Convert hex to turn ASCII BX high four (i.e. one hexadecimal number) of ASCII value, in order to use DOS function calls, output
CMP al, 3 ah; Is it> 9? The ASCII ASCII is greater than the number 9?
Jl printit_n; Jump if digit=0 to 9 is not jump to printit directly output
The add al, 7 h; Digit is A to F the number of hexadecimal ASCII is greater than A - F number 9, to A letter corresponding ASCII code, this is the computer stored in A binary number
Output to uppercase letters, also can output the lowercase letters,
Printit_n:
Mov dl, al; Put the ASCII char in DL call DOS system function calls, shows that the output character of DL
Mov ah, 2; The display output funct
Int h; Call DOS
Inc ch; 4 who done? Mobile BX from left to right all points of the content of the four groups?
CMP ch, 4
Developed rotate_n; All the not yet finished mobile content of BX, continue to move

Pop dx
Pop cx
Pop ax

Ret. Return the to DOS returns to the DOS
BinHexN endp; The end of the main part of prog. End of the main program

Prognam ends; End of the end of the segment code

end

CodePudding user response:

Masm b.a sm cannot produce b.o bj will be prompted to which there is an error line, such as the first line will think that is no definition of pubic, carefully Chou Chou binihexn and BinHexN is not the same as below, there are the same, the annotation line, don't add annotation symbols - English semicolons,
  • Related