|
Page 1 of 1
|
[ 5 posts ] |
|
Author |
Message |
64RB463_F173
Joined: Fri Jan 15, 2010 1:30 pm Posts: 2 Location: w1nf137d, 1771n01s
|
C to Asm
I keep getting told that C is so much simpler to use but the logic of ASM makes so much more sense to me and for some reason C just seem sto confuse the hell out of me so since all the tutorials i read are pretty much in C/C++ im trying to convert it to ASM but im not positive if this is correct or not: C code from http://www.jamesmolloy.co.uk/tutorial_html/3.-The%20Screen.htmlCode: // Updates the hardware cursor. static void move_cursor() { // The screen is 80 characters wide... u16int cursorLocation = cursor_y * 80 + cursor_x; outb(0x3D4, 14); // Tell the VGA board we are setting the high cursor byte. outb(0x3D5, cursorLocation >> 8); // Send the high cursor byte. outb(0x3D4, 15); // Tell the VGA board we are setting the low cursor byte. outb(0x3D5, cursorLocation); // Send the low cursor byte. } and my ASM version: Code: mov ax, X_VALUE mov bx, Y_VALUE
move_cursor: ; mov dx,bx ; copy bx (y) to dx shl bx,6 ; bx * 64 shl dx,4 ; dx * 16 add dx,bx ; add both together (y * 80) add ax,dx ; add dx to ax (y*80 + x) ; out 0x3d4, 14 ; tell vga to set high byte out 0x3d5, ah ; send high byte out 0x3d4, 15 ; tell vga to set low byte out 0x3d5, al ; send low byte
_________________ ..##6##4##r##b##4##6##3################ .#...insignificance is a detail that is often over looked..# ######################f##1##7##3####
|
Fri Jan 15, 2010 2:49 pm |
|
|
DudeOfX
Joined: Sat Jul 25, 2009 9:15 am Posts: 257
|
Re: C to Asm
well thats an interesting argument... and btw you also have an interesting user ID... your assembly looks right thou... I like assembly because there is no ambiguity...
|
Fri Jan 15, 2010 9:01 pm |
|
|
Arlen
Joined: Sat Jan 16, 2010 7:53 pm Posts: 18 Location: Melbourne, Australia
|
Re: C to Asm
Honestly, there's no ambiguity either, in C (or C++), as long as you understand the quirks and how the language works and compiles down into assembly. Unfortunately, there are many of those, but a strong knowledge of same means you can be much more efficient coding. (that's why higher-level languages exist!)
|
Sat Jan 16, 2010 8:10 pm |
|
|
XanClic
Joined: Thu Jan 07, 2010 4:46 am Posts: 5
|
Re: C to Asm
I'm aware that this code won't even assemble: Code: out 0x3d4, 14 ; tell vga to set high byte out 0x3d5, ah ; send high byte out 0x3d4, 15 ; tell vga to set low byte out 0x3d5, al ; send low byte If the port number doesn't fit in a byte, you have to put it into DX and use that register. Furthermore you may only output AL and no other value (neither a constant value nor another register nor a memory area). So try it this way: Code: push ax mov al,14 mov dx,0x3D4 out dx,al inc dx mov al,ah out dx,al dec dx mov al,15 out dx,al inc dx pop ax out dx,al Hope that helps.
|
Wed Jan 20, 2010 10:44 am |
|
|
64RB463_F173
Joined: Fri Jan 15, 2010 1:30 pm Posts: 2 Location: w1nf137d, 1771n01s
|
Re: C to Asm
Ok yeah i over looked that (or am ignorant) thanx, makes sense tho. Code: push ax mov al,14 mov dx,0x3D4 out dx,al inc dx mov al,ah out dx,al dec dx mov al,15 out dx,al inc dx pop ax out dx,al
Ive just recently started learning about using ports in asm so..... Thanx for all the replies.
_________________ ..##6##4##r##b##4##6##3################ .#...insignificance is a detail that is often over looked..# ######################f##1##7##3####
|
Sun Jan 24, 2010 2:53 am |
|
|
|
Page 1 of 1
|
[ 5 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 3 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|