1

I'm working on emulator, which should emulated specific program. I have COM file and source file. Now I need to emulate this specific instruction (this is what I can see in DosBox debugger):

mov cl, [017B]        8A 0E 7B 01

I know it means to move value from DS (data segment) with offset 017B into CL register. But what should be in DS?

Program I'm trying to emulate (source file):

.386p

.model tiny

code    segment use16
    assume cs:code
    org  100h

begin:
  mov ax, 3h
  int 10h
...
  mov cl, byte ptr ds:[keylen]   <-- This is the instruction I'm talking about
...
  int 20h           

keylen db 13
key1 db 20h, 3ah, 23h, 32h, 0bh, 3dh, 1fh, 13h, 4ch, 19h, 05h, 07h, 07h, 00h
key2 db 00h, 0ah, 11h, 08h, 03h, 1dh, 1ah, 08h, 04h, 2ch, 3fh, 33h, 1ah, 41h
key3 db 01h, 00h, 08h, 0bh, 0ch, 07h, 0ah, 05h, 02h, 09h, 06h, 03h, 04h, 00h

code    ends
end begin

What should I save into DS when I start my program? Only think I'm doing now is to set DS = CS = ES = SS = SPECIFIC_ADDRESS

3
  • 4
    With a COM program (tiny model with an org of 100h`) CS=DS=ES=SS=the segment of the PSP you use for the program before you transfer control to it. This only applies to COM (not EXE) Commented Dec 24, 2017 at 21:57
  • This may be of some use to you: fysnet.net/yourhelp.htm (plus maybe PSP structure, if the code is fetching something from cs:0000-cs:00FF range). Commented Dec 24, 2017 at 21:59
  • @MichaelPetch I know, it is COM program Commented Dec 24, 2017 at 22:02

1 Answer 1

2

For a .COM program like the one you have, there's no need to want to setup any of the segment registers yourself. The operating system program loader has already set them all pointing at the start of your program.

The instruction mov cl, byte ptr ds:[keylen] will work as is.
You don't even have to specify the segment explicitly. You can also write mov cl, byte ptr [keylen] or even mov cl, [keylen].

Now if you insist on setting up the DS segmentregister manually, you could write:

mov ax, cs
mov ds, ax

Another way would be:

mov ah, 62h   ;DOS.GetPSP
int 21h       ; -> BX
mov ds, bx
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for reply. I'm not sure if you get point of my question. I'm trying to emulate this program and I know where I should point DS. But I don't know what should be in whole data section.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.