SuperHippo
SuperHippo

Reputation: 1

8086 Program print your name as array of hex values of ascii using loop

Here is my code, but when I use my debugger I get an error once I reach the int21 h command which says:

Unhandled exception at 0x00007FF6E9B01034 in MP2_KyleRuiter.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

Program:

ExitProcess PROTO

.data 

string DB 4bh, 79h, 6ch, 65h, 20h, 52h, 75h, 69h, 74h, 65h, 72h, 00h ; My Name

COUNT = ($-string) ; string length calculation

.code

main proc

 mov rcx,COUNT ; loop counter

 mov rsi,offset string 

 L1:

 mov dl,[rsi] ;gets character from the array

  mov ah,2 ;displays character

 inc rsi; points to next character

 Loop L1 ;decrements rcx until 0

 mov rax, 4c00h

 int 21h ; displays

RET
main ENDP

END 

Upvotes: 0

Views: 766

Answers (3)

user149341
user149341

Reputation:

You can't use DOS interrupts, like int 21h, in a 64-bit Windows executable. Modern Windows isn't a DOS-based system, so it doesn't use that interface anymore.

If you want to write a DOS executable, you'll need to use 16-bit instructions, and run it in an emulator (like DOSBox).

If you want to write a 64-bit Windows executable, you'll need to use Windows library calls.

Pick one.

Upvotes: 1

donjuedo
donjuedo

Reputation: 2505

int 21h with AH set to 4Ch says to terminate with a return code. It looks like your debugger does not know how to step over/into a terminate. That makes some sense, I suppose.

Belay my last. I stand corrected.

You might find this helpful, though: Why does using "int 21h" on Assembly x86 MASM cause my program to crash?

Upvotes: 0

Matteo Italia
Matteo Italia

Reputation: 126827

int 21h & co. is 16-bit MS-DOS stuff, while the rest of the code you wrote is x86 64bit assembly. On 64-bit Windows you are invoking god-knows-what interrupt handler, which results in a crash.

If you want to print stuff when running under 64 bit Windows you have to invoke the relevant syscalls (GetStdHandle to get a handle to the console, WriteFile to write the data); MASM makes this relatively simple through the INVOKE directive.

Upvotes: 3

Related Questions