- English -
Resident Freddy
- Joined
- Apr 7, 2004
- Messages
- 5,263
Ive been trying all today to learn how to use subroutines. Firstly im using the NASMIDE compiler. From what Ive been reading, a subroutine is like a function, method etc which can be called several times.
Ok, so this program prints the character A. Now I have to do the same using sub routines. In C, i can imagine making a function
Now if I do this with assembly
Yes It prints the character A, but I dont think this is a subroutine, anyone who knows assembly can help?
Code:
BITS 16 ;Set code generation to 16 bit mode
ORG 0x0100 ;Set code start address to 0100h
SECTION .text ;Main code segment
MAIN:
MOV DL, 'A' ;Moving "A" in DL register
MOV AH, 02H
INT 21H ;Tells DOS to execute
MOV DH, DL ;moves DL(A) into DH register
mov AX, 04C00H ;This function exits the program
int 21H
SECTION .data ;data segment for initialised data & constants
SECTION .bss ;data segment for uninitialised data
Ok, so this program prints the character A. Now I have to do the same using sub routines. In C, i can imagine making a function
Code:
main()
{
calla();
}
calla()
{
printf("A");
}
Code:
BITS 16 ;Set code generation to 16 bit mode
ORG 0x0100 ;Set code start address to 0100h
SECTION .text ;Main code segment
MAIN:
call LABEL
call EXITLABEL
LABEL:
MOV DL, 'A' ;Moving "A" in DL register
MOV AH, 02H
INT 21H ;Tells DOS to execute
MOV DH, DL ;moves DL(A) into DH register
EXITLABEL:
mov AX, 04C00H ; This function exits the program
int 21H
SECTION .data ; data segment for initialised data & constants
SECTION .bss ; data segment for uninitialised data
Yes It prints the character A, but I dont think this is a subroutine, anyone who knows assembly can help?