0

I am just testing and trying to learn how assembler works with C. So i was browsing around some tutorials and i found this:

__asm
{
    mov     ax,0B800h       //startaddress for the screen memory (in textmode)
    mov     es,ax           //add the startaddress to es

    xor     di,di           //reset di (start at the beginning of the screen)

    mov     al, 65          //65 = ascii for the 'A' character to al
    mov     ah, 16*4+1      //Attribute = blue text on a red background to ah.
    mov     cx,2000         //25*80 = 2000 characters on the screen
    rep     stosw           //write ax to the screen memory and count di up 2000 times

}

The problem i have is that i can't run it, i can compile it inside my main method in Microsoft Visual Studio 2008 but when i run it, it produces this error:

Unhandled exception at 0x00da3660 in Test.exe: 0xC0000005: Access violation reading location 0xffffffff.

on the second line, mov es,ax //lägg startadressen i es

Could it be that the program is 16-bit and that VS 2008 compiles it into a 32-bit program? If so, can you force VS 2008 to compile it differently?

Does anyone know of a good inside assembler tutorial ?

1
  • 1
    please translate the comments into english so that everybody can understand them Commented Sep 1, 2009 at 11:22

6 Answers 6

4

It is 16 bit DOS code assuming a lot of things which aren't true anymore for a long time. You should better search for some other tutorial.

Sign up to request clarification or add additional context in comments.

1 Comment

It's a long time since I learned it. If I remember correctly, The Art of Assembly Language of Randall Hyde wasn't bad, even if that author had it pet peeves. homepage.mac.com/randyhyde/webster.cs.ucr.edu/index.html seems his current location on the web
1

Hello I found a very good tutorial!, it explains with simple diagrams every detail.

It's exactly what you are looking for :)!

http://rodrigosavage.blogspot.com/2010/07/hello-world-with-inline-asm.html

Comments

1

I rewrite your code as:

[BITS 16]
[ORG 7C00h]
main:

mov     ax,0B800h
mov     es,ax
xor     di,di
mov     al, 65
mov     ah, 16*4+1
mov     cx,2000
rep     stosw

times 510-($-$$) db 0
dw 0xAA55

Then save it as xxx.asm, and compile it using "nasm xxx.asm", and subsequently run this inside kvm: "kvm xxx" or you can also "dd" to your harddisk, and boot up directly from the the code and see it running. All done inside Ubuntu environment. There are many more similar examples to above here:

Gavin's Guide to 80x86 Assembly - Part 7:

http://stuff.pypt.lt/ggt80x86a/asm8.htm

Comments

0

rep stosw repeats storing a word from ax to es:di, and your es:di is B800:0 which is arbitrary in protected mode and it may not be mapped in your program, so it gives a segmentation fault. It looks like an ancient code. If you have DOS, it might just work

Comments

0

Windows does not allow direct access to video memory. If you want to work in console, you should use console related API.

Comments

0

This is DOS code. For learning Win32 assembly, the 'classics' are Iczelion's tutorials. Have a look here

Comments

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.