Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More examples related to memory based addressing #22

Open
swagatk opened this issue Feb 24, 2022 · 6 comments
Open

More examples related to memory based addressing #22

swagatk opened this issue Feb 24, 2022 · 6 comments

Comments

@swagatk
Copy link

swagatk commented Feb 24, 2022

Hi All,
This is a very useful project. It works most of the time. It would be a great idea to include more examples to explain various capabilities of this emulator - memory addressing, loading and storing values into the memory etc. For instance, I am trying to load a set of bytes from the memory and then perform add with carry on these bytes as mentioned in this example.

data:   DB 0x16
           DB 0xFC
           DB 0x97
           DB 0x84

start:
    MOV BP, OFFSET data
    MOV AL, BYTE [BP]
    INC BYTE [BP]     ;  I want to increment the address stored in BP to access the next byte
    MOV BL, BYTE [BP] ; It copies the value at the previous byte

My question is how can I load a series of bytes from the memory using data segment register or SI/DI registers. In other words, how can increment the memory addresses. One would be to use addresses directly [01], [02] etc. But it will be good to increment the BP register to go to the next address. In short, It would really help if you can create a tutorial on this providing more examples.

thanks for this great work. really appreciate for your effort. I am using this software to teach my students.

Regards,
Swagat

@YJDoc2
Copy link
Owner

YJDoc2 commented Feb 24, 2022

Hey!

This is a very useful project.

Very happy to hear that you are finding this useful , thank you!

It works most of the time.

There are some limitations of this projects, but some issues might be bugs as well, so if you find any, please feel free to open issues 👍

To increment the memory address you can use the INC command as well : INC SI

From what we understood from your question, we have written a simple program , which might be similar to what you are looking for :

; Program to add two word length numbers
val1:
DB 0x16
DB 0xFC
val2:
DB 0x97
DB 0x84

; actual entry point of the program
start:
MOV SI, OFFSET val1
MOV DI, OFFSET val2
;Lower 
MOV AL, byte [SI]
INC SI
MOV BL, byte [DI]
INC DI
ADC AL,BL
DAA
MOV DL, AL
;higher
MOV AL, byte [SI]
INC SI
MOV BL, byte [DI]
INC DI
ADC AL,BL
MOV DH, AL

In case you meant something different, please let us know we'll try to help as much as we can.

It would be a great idea to include more examples to explain various capabilities of this emulator

We have some demo examples in to core library repository at https://github.com/YJDoc2/8086-Emulator/tree/master/examples

You can also take a look at the instructions page https://yjdoc2.github.io/8086-emulator-web/help which explains supported syntax of each instruction.

Hope this helps,
Let know if you have any other issues or doubts :)

@swagatk
Copy link
Author

swagatk commented Feb 27, 2022 via email

@YJDoc2
Copy link
Owner

YJDoc2 commented Mar 7, 2022

Hey @swagatk ,
Apologies for the late reply 😓

I wrote a crude way to check if a number is prime or not. If you find this
program correct, you may include this in your examples.

I would be happy to include the example, but I am not able to find it. Have you attached it to the message or have you put it in some separate repository/gist?

Also, if you would be fine with it, can you tell in which university/college and for which course are you using this for teaching? I am just curious as to how useful this is for it 😅 😅

Thanks :)

@swagatk
Copy link
Author

swagatk commented Mar 7, 2022 via email

@Vatsalsoni13
Copy link
Collaborator

Vatsalsoni13 commented Mar 8, 2022

Hello @swagatk,
I'm Vatsal Soni one of the contributor/developer of this project. First of all, we are very happy that you found this emulator useful. So, I went through your code for checking if the number is prime or not, I found two small edge cases missing which I have added and wanted to let you know just in case. When 0 or 1 is entered as input in previous code it used to go in the loop1 and first decrement of CH register takes place which created error when DIV is run as it becomes DivisionByZero.
I have added the corrected code below.

; checking if a given number is prime or not
; it should work for any decimal number between 0 and 255.
start:
        MOV DL, 0       ; used for compare with 0
        MOV DH, 1       ; used for compare with 1
        MOV CL, 0       ; enter the number (n) for checking prime-ness
        MOV CH, CL      ; CH <-- CL
        
        CMP CH, DH       
        JZ zeroAndOneCheck ; if 1 is entered as input then its not prime goto zeroAndOneCheck
        
        CMP CH, DL
        JZ zeroAndOneCheck ; if 0 is entered as input then its not prime goto zeroAndOneCheck

loop1:  DEC CH          ; start with CH = n-1 as divisor
        CMP CH, DH      ; continue until CH = 1
        JZ  skip        ; if CH == 1, jump to skip (end loop)
        MOV AL, CL      ; copy the value from CL TO AL everytime
        MOV AH, 0x00    ; clear remainder everytime before division
        DIV CH          ; AL / CH, check remainder in AH
        CMP AH, DL      ; if remainder (AH) is not zero, jump to loop1
        JNZ loop1
        MOV BL, 0       ; BL=0 Indicates the number is not prime
        HLT
skip:   MOV BL, 1       ; BL=1 Indicates the number is prime
        HLT
zeroAndOneCheck:   HLT  

Thanks a lot for your contribution, we appreciate it :)

@YJDoc2
Copy link
Owner

YJDoc2 commented Mar 8, 2022

Also to add another thing, we will be adding the example under MIT + Apache 2.0 dual license, same as the emulator-8086 repository : https://github.com/YJDoc2/8086-Emulator/#license . In case you have any issue with this, let us know. Otherwise, feel free to close this issue :)
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants