As a simple test, I wanted to see how much faster ASM was than C, so I decided to compare printf to Display String function 9. I was surprised to see that ASM displayed 0xFFFF strings in 3 seconds compared to the 21 seconds it took in C. Is this kind of speed difference normal? Also can C ever be as fast as ASM when it comes to displaying strings? Its written as real mode flat model. Is my ASM code wrong or is there a huge speed difference between C and ASM?
edit : Also tried creating the string before printf - same result
Compiled with GCC
Here is the code
#include <stdio.h>
int main(){
for(register int x=0; x < 0xFFFF; x++){
printf("FF is now a string\n");
}
}
[BITS 16]
[ORG 0x100]
%include "Byte2Str.MAC"
[SECTION .text]
mov AL,0xFF ;load number into AL (ByteToString uses AL)
mov SI,msg ;Load address of string
ByteToString ;converts a 1 byte number into a 2 byte string
mov DX,msg
mov AX,0x0900 ;Function 9 - printstring
mov CX,0xFFFF ;Loop 0xFFFF Times
looptop:
dec CX
INT 0x21 ;DOS Dispatcher
jnz looptop
mov AX,0x4C00 ;0x4C00 - Terminate Program
int 0x21 ;Dos Dispatcher
[SECTION .data]
Digits db '0123456789ABCDEF'
msg db " is now a string!",13,10,'$'