<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>x86 Assembly Forum RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest threads from the 'x86 Assembly' forum at Programmer's Heaven, excluding replies.</description>
    <language>en</language>
    <copyright>Copyright 2012 Programmers Heaven</copyright>
    <pubDate>Thu, 09 Feb 2012 03:57:47 -0800</pubDate>
    <lastBuildDate>Thu, 09 Feb 2012 03:57:47 -0800</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>STATUS FLAG. Need help fast:)</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/426274/426274/status-flag-need-help-fast/</link>
      <description>Hi all. I want to check the Status Flag after a command but it gives wrong values! For example:&lt;br /&gt;
After adding 126 with 127 Status Flag would be FFBA, BUT...&lt;br /&gt;
when i run this code, it gives 7112:&lt;br /&gt;
&lt;br /&gt;
        mov ax, 126&lt;br /&gt;
	mov bx, 127&lt;br /&gt;
	PUSHF&lt;br /&gt;
	MOV dx, 0FFFFh&lt;br /&gt;
	PUSH dx&lt;br /&gt;
	POPF&lt;br /&gt;
	add ax, bx&lt;br /&gt;
	PUSHF&lt;br /&gt;
	POP ax&lt;br /&gt;
	POPF&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/426274/426274/status-flag-need-help-fast/</guid>
      <pubDate>Mon, 12 Dec 2011 07:47:20 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>STATUS FLAG. Need help fast:)</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/426273/426273/status-flag-need-help-fast/</link>
      <description>Hi all. I want to check the Status Flag after a command but it gives wrong values! For example:&lt;br /&gt;
After adding 126 with 127 Status Flag would be FFBA, BUT...&lt;br /&gt;
when i run this code, it gives 7112:&lt;br /&gt;
&lt;br /&gt;
        mov ax, 126&lt;br /&gt;
	mov bx, 127&lt;br /&gt;
	PUSHF&lt;br /&gt;
	MOV dx, 0FFFFh&lt;br /&gt;
	PUSH dx&lt;br /&gt;
	POPF&lt;br /&gt;
	add ax, bx&lt;br /&gt;
	PUSHF&lt;br /&gt;
	POP ax&lt;br /&gt;
	POPF&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/426273/426273/status-flag-need-help-fast/</guid>
      <pubDate>Mon, 12 Dec 2011 07:45:29 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>Keyboard Interrupt to detect Space, right and left arrow keys</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/426037/426037/keyboard-interrupt-to-detect-space-right-and-left-arrow-keys/</link>
      <description>Hello. I have a homework. My development environment: Turbo C++ 3.0&lt;br /&gt;
and programming Language Assembly, ANSI C. I have to detect when the user press Space or right or left arrow keys. It is forbidden that using "dos.h" and "int 21H" &lt;br /&gt;
I have found this information but I could not understand how to implement it :&lt;br /&gt;
&lt;br /&gt;
When a key is pressed on keyboard, an interrupt along with a scan code named “make code” is produced and when the key released a “break code” is produced by the keyboard controller. On a PC, keyboard is controlled by a chip and assigned to port numbers 60h and 61h. When a key is pressed on keyboard, scan value is put in register at 60h. You can get this scan code with the following command: in al,60h After getting the scan code, you have to reset the keyboard programming the command register of the chip at 61h with following commands: in al,61h or al,82h out 61h,al and al,7fh out 61h,al At the end of every interrupt service routine, you clear PIC service bit, sending End Of Interrupt (EOI) command, 20h to PIC port at address 20h. mov al,20h out 20h,al&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/426037/426037/keyboard-interrupt-to-detect-space-right-and-left-arrow-keys/</guid>
      <pubDate>Fri, 02 Dec 2011 15:54:54 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>Keyboard Interrupt to detect Space, right and left arrow keys</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/426036/426036/keyboard-interrupt-to-detect-space-right-and-left-arrow-keys/</link>
      <description>Hello. I have a homework. My development environment: Turbo C++ 3.0&lt;br /&gt;
and programming Language Assembly, ANSI C. I have to detect when the user press Space or right or left arrow keys. It is forbidden that using "dos.h" and "int 21H" &lt;br /&gt;
I have found this information but I could not understand how to implement it :&lt;br /&gt;
&lt;br /&gt;
When a key is pressed on keyboard, an interrupt along with a scan code named “make code” is produced and when the key released a “break code” is produced by the keyboard controller. On a PC, keyboard is controlled by a chip and assigned to port numbers 60h and 61h. When a key is pressed on keyboard, scan value is put in register at 60h. You can get this scan code with the following command: in al,60h After getting the scan code, you have to reset the keyboard programming the command register of the chip at 61h with following commands: in al,61h or al,82h out 61h,al and al,7fh out 61h,al At the end of every interrupt service routine, you clear PIC service bit, sending End Of Interrupt (EOI) command, 20h to PIC port at address 20h. mov al,20h out 20h,al&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/426036/426036/keyboard-interrupt-to-detect-space-right-and-left-arrow-keys/</guid>
      <pubDate>Fri, 02 Dec 2011 15:53:04 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>To create a file is not working with this method</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/425978/425978/to-create-a-file-is-not-working-with-this-method/</link>
      <description>&lt;pre class="sourcecode"&gt;
-a
0C89:0100 jmp 111
0C89:0102
-e 102 db 'C:\exam.txt',0
-a 111
0C89:0111 mov ah,3c
0C89:0113 mov cx,0
0C89:0116 mov dx,102
0C89:0119 int 21
0C89:011B mov ah,4c
0C89:011D int 21
0C89:011F
-h 11f 100
021F  001F
-rcx
CX 0000
:001f
-n filecr.com
-w
Writing 0001F bytes 
-q

C:\&amp;gt;filecr

C:\&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
How can i a create file in 32-bit system with debugger in ms-dos?&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/425978/425978/to-create-a-file-is-not-working-with-this-method/</guid>
      <pubDate>Sun, 27 Nov 2011 18:45:10 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>assambly matrix program</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/425761/425761/assambly-matrix-program/</link>
      <description>Hello. I had a task to write a program which finds minimal elements in each matrix column. I kinda wrote program, but when i check results they are kinda different.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;.model tiny
.code
.startup
                Org      100h
                Jmp Short Start
N Equ  2
M  Equ 3
Matrix DW 1, 7, 3   ; 2 elementi diapazonв [Min, Max]
DW 4, 5, 6   ; 3 elementi diapazonв [Min, Max]
Vector DW M Dup (?)
S Equ Type Matrix
Start:
Xor Bx, Bx
Mov Cx, M
Lea Di, Vector
Cols: Push      Cx
Mov Cx, N
Xor Si, Si
Xor Ax, Ax
Xor      Dx, Dx
Mov  Ax , Matrix[Bx][Si]
Rows:
 
   Cmp Matrix[Bx][Si], Ax
Jg False
Mov  Ax,  Matrix[Bx][Si]
 
False:
Add Si, S*M
Loop Rows
Mov [Di], Ax
Add Bx, S
Add Di, S
                Pop      Cx
Loop Cols
Xor Bx, Bx
Mov Cx, M
Print: Mov Ax, Vector[Bx]
Add Bx, S
Loop Print
          
.exit 0
end&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Could someone point out or help me correct my mistakes?&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/425761/425761/assambly-matrix-program/</guid>
      <pubDate>Sun, 13 Nov 2011 11:52:02 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>assambly matrix program</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/425760/425760/assambly-matrix-program/</link>
      <description>Hello. I had a task to write a program which finds minimal elements in each matrix column. I kinda wrote program, but when i check results they are kinda different.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;.model tiny
.code
.startup
                Org      100h
                Jmp Short Start
N Equ  2
M  Equ 3
Matrix DW 1, 7, 3   ; 2 elementi diapazonв [Min, Max]
DW 4, 5, 6   ; 3 elementi diapazonв [Min, Max]
Vector DW M Dup (?)
S Equ Type Matrix
Start:
Xor Bx, Bx
Mov Cx, M
Lea Di, Vector
Cols: Push      Cx
Mov Cx, N
Xor Si, Si
Xor Ax, Ax
Xor      Dx, Dx
Mov  Ax , Matrix[Bx][Si]
Rows:
 
   Cmp Matrix[Bx][Si], Ax
Jg False
Mov  Ax,  Matrix[Bx][Si]
 
False:
Add Si, S*M
Loop Rows
Mov [Di], Ax
Add Bx, S
Add Di, S
                Pop      Cx
Loop Cols
Xor Bx, Bx
Mov Cx, M
Print: Mov Ax, Vector[Bx]
Add Bx, S
Loop Print
          
.exit 0
end&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Could someone point out or help me correct my mistakes?&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/425760/425760/assambly-matrix-program/</guid>
      <pubDate>Sun, 13 Nov 2011 11:50:11 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>Test</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/425695/425695/test/</link>
      <description>This is a test.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/425695/425695/test/</guid>
      <pubDate>Thu, 10 Nov 2011 07:42:25 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>linked lists</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/425317/425317/linked-lists/</link>
      <description>hey all!&lt;br /&gt;
i'm new here..&lt;br /&gt;
i'm new to assmebly and we will apparently have linked lists in our exam - even though we weren't taught in class due to lack of time. :-\&lt;br /&gt;
&lt;br /&gt;
can anyone give me some link,simple example, or a little insight as to what i must know?&lt;br /&gt;
i searched the web myself...but didn't find much.. &lt;img src="http://www.programmersheaven.com/images/Community/frown.gif" width="15" height="15" alt="" /&gt;&lt;br /&gt;
&lt;br /&gt;
i know how to do linked lists in c language...&lt;br /&gt;
&lt;br /&gt;
thanks in advance !&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/425317/425317/linked-lists/</guid>
      <pubDate>Wed, 19 Oct 2011 14:51:08 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>16-bit binary to decimal</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/425307/425307/16-bit-binary-to-decimal/</link>
      <description>How can i convert 16-bit binary to decimal. So basically i want to put a 16-bit binary number, in lets say registry dx. Then i want to print that number, but the printed value should be in decimals. So how can i do that??? any ideas ?&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/425307/425307/16-bit-binary-to-decimal/</guid>
      <pubDate>Tue, 18 Oct 2011 15:34:53 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>x86 assembly Intel Syntax</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/425267/425267/x86-assembly-intel-syntax/</link>
      <description>This is my code so far for a multiply function that cannot use any multipaction and division operators. &lt;br /&gt;
&lt;br /&gt;
 .intel_syntax  noprefix&lt;br /&gt;
 .data&lt;br /&gt;
&lt;br /&gt;
 .globl _x&lt;br /&gt;
_x: .long 0   &lt;br /&gt;
&lt;br /&gt;
 .global _y&lt;br /&gt;
_y: &lt;br /&gt;
&lt;br /&gt;
 .text&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 .globl _fac &lt;br /&gt;
_fac:&lt;br /&gt;
 push ebp    &lt;br /&gt;
 mov ebp,esp&lt;br /&gt;
 &lt;br /&gt;
 mov eax,0   &lt;br /&gt;
 mov edx,1&lt;br /&gt;
 mov     ebx,_x&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 mov ecx,_y&lt;br /&gt;
&lt;br /&gt;
 cmp edx,ecx&lt;br /&gt;
 jl LOOP&lt;br /&gt;
 xchg ecx,ebx&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
       &lt;br /&gt;
LOOP: &lt;br /&gt;
  &lt;br /&gt;
 cmp edx,ecx&lt;br /&gt;
 jg DONE&lt;br /&gt;
 add eax,ebx&lt;br /&gt;
 SUB ecx,1&lt;br /&gt;
&lt;br /&gt;
 jmp LOOP&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
DONE: &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 pop ebp #you need this too&lt;br /&gt;
 ret  #return&lt;br /&gt;
&lt;br /&gt;
It works with a main.c file that calls multiply and calls the global variables x and y &lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/425267/425267/x86-assembly-intel-syntax/</guid>
      <pubDate>Fri, 14 Oct 2011 10:06:18 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>x86 assembly Intel Syntax</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/425266/425266/x86-assembly-intel-syntax/</link>
      <description>This is my code so far for a multiply function that cannot use any multipaction and division operators. &lt;br /&gt;
&lt;br /&gt;
 .intel_syntax  noprefix&lt;br /&gt;
 .data&lt;br /&gt;
&lt;br /&gt;
 .globl _x&lt;br /&gt;
_x: .long 0   &lt;br /&gt;
&lt;br /&gt;
 .global _y&lt;br /&gt;
_y: &lt;br /&gt;
&lt;br /&gt;
 .text&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 .globl _fac &lt;br /&gt;
_fac:&lt;br /&gt;
 push ebp    &lt;br /&gt;
 mov ebp,esp&lt;br /&gt;
 &lt;br /&gt;
 mov eax,0   &lt;br /&gt;
 mov edx,1&lt;br /&gt;
 mov     ebx,_x&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 mov ecx,_y&lt;br /&gt;
&lt;br /&gt;
 cmp edx,ecx&lt;br /&gt;
 jl LOOP&lt;br /&gt;
 xchg ecx,ebx&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
       &lt;br /&gt;
LOOP: &lt;br /&gt;
  &lt;br /&gt;
 cmp edx,ecx&lt;br /&gt;
 jg DONE&lt;br /&gt;
 add eax,ebx&lt;br /&gt;
 SUB ecx,1&lt;br /&gt;
&lt;br /&gt;
 jmp LOOP&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
DONE: &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 pop ebp #you need this too&lt;br /&gt;
 ret  #return&lt;br /&gt;
&lt;br /&gt;
It works with a main.c file that calls multiply and calls the global variables x and y &lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/425266/425266/x86-assembly-intel-syntax/</guid>
      <pubDate>Fri, 14 Oct 2011 10:04:28 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>Add 2 hex values and display the result</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/425150/425150/add-2-hex-values-and-display-the-result/</link>
      <description>I have to write a program where the user inputs 2 individual hex values, 0-9 and A-F.  The program must then add them and display the result in hex.  In the following code I allready took care of 0-9 but now I have to add code where the user can input A-F or a-f.  I think that I need to add another loop but I'm stuck on where to put it and how.  Any help is apprecdiated.&lt;br /&gt;
&lt;br /&gt;
 BOZOS_CODE SEGMENT&lt;br /&gt;
             &lt;br /&gt;
	     ASSUME CS:BOZOS_CODE&lt;br /&gt;
             ORG 100h            &lt;br /&gt;
           START: jmp begin      &lt;br /&gt;
 &lt;br /&gt;
     ;Our data area starts here&lt;br /&gt;
           message_1   db 'The first digit please (0 - 9): $'&lt;br /&gt;
	   message_2    db 'The second digit please (0 - 9): $'&lt;br /&gt;
           message_res  db 'The result of the addition is: $'&lt;br /&gt;
           message_exit db 'Do you wish to do another addition (Y or N)?: $'&lt;br /&gt;
           first_num  db 0&lt;br /&gt;
           second_num db 0&lt;br /&gt;
           result     db 'xx$'  &lt;br /&gt;
&lt;br /&gt;
     &lt;br /&gt;
&lt;br /&gt;
           begin: mov ax, cs     ;Beginning of program...Make DS point to CS&lt;br /&gt;
                  mov ds, ax     ; since data area is in CS&lt;br /&gt;
&lt;br /&gt;
        ;Clear the display&lt;br /&gt;
          goofey: mov ah, 06h    ;Scroll up window function&lt;br /&gt;
                  mov al, 0      ; Clear entire window&lt;br /&gt;
                  mov bh, 00011100b ; Display "attribute byte" for cleared area&lt;br /&gt;
                                &lt;br /&gt;
                  mov ch, 0      ;  Y = 0  (Upper left-hand corner X &amp;amp; Y)&lt;br /&gt;
                  mov cl, 0      ;  X = 0&lt;br /&gt;
                  mov dh, 24     ;  Y = 24 (Lower right-hand corner X &amp;amp; Y)&lt;br /&gt;
                  mov dl, 79     ;  X = 79&lt;br /&gt;
                  int 10h        ;Call BIOS procedure to clear the display&lt;br /&gt;
        &lt;br /&gt;
	;Set cursor position&lt;br /&gt;
                  mov ah, 02h    ;Set cursor position function&lt;br /&gt;
                  mov bh, 0      ; Display page 0&lt;br /&gt;
                  mov dh, 10     ; Y = 10  (Row position where Y: 0 -&amp;gt; 24)&lt;br /&gt;
                  mov dl, 10     ; X = 10  (Column position where X: 0 -&amp;gt; 79)&lt;br /&gt;
                  int 10h        ;Call BIOS procedure to set the cursor position&lt;br /&gt;
 &lt;br /&gt;
        ;Request first number&lt;br /&gt;
                  mov ah, 09h            ;Display string function&lt;br /&gt;
                  mov dx, offset message_1;Pass the starting address of string&lt;br /&gt;
                  int 21h                ;Call DOS to display a message&lt;br /&gt;
        ;Get first number&lt;br /&gt;
                  mov ah, 00h    ;Read keyboard function&lt;br /&gt;
                  int 16h        &lt;br /&gt;
&lt;br /&gt;
                                 ;AL now contains ASCII code of key pressed&lt;br /&gt;
                  mov first_num, al  ;Copy the ASCII code of the key pressed&lt;br /&gt;
                                     ; into the memory location ‘first_num’&lt;br /&gt;
&lt;br /&gt;
        ;Set cursor position&lt;br /&gt;
                  mov ah, 02h    ;Set cursor position function&lt;br /&gt;
                  mov bh, 0      ; Display page 0&lt;br /&gt;
                  mov dh, 11     ; Y = 11&lt;br /&gt;
                  mov dl, 10     ; X = 10&lt;br /&gt;
                  int 10h        ;Call BIOS procedure to set the cursor position&lt;br /&gt;
&lt;br /&gt;
        ;Request second number&lt;br /&gt;
                  mov ah, 09h            ;Display string function&lt;br /&gt;
                  mov dx, offset message_2;Pass the starting address of string&lt;br /&gt;
                  int 21h                ;Call DOS to display a message&lt;br /&gt;
&lt;br /&gt;
        ;Get second number&lt;br /&gt;
                  mov ah, 00h    ;Read keyboard function&lt;br /&gt;
                  int 16h        &lt;br /&gt;
&lt;br /&gt;
                                 ;AL now contains ASCII code of key pressed&lt;br /&gt;
                  mov second_num, al  ;Copy the ASCII code of the key pressed&lt;br /&gt;
                                      ; into the memory location ‘second_num’&lt;br /&gt;
&lt;br /&gt;
        ;Set cursor position&lt;br /&gt;
                  mov ah, 02h    ;Set cursor position function&lt;br /&gt;
                  mov bh, 0      ; Display page 0&lt;br /&gt;
                  mov dh, 12     ; Y = 12&lt;br /&gt;
                  mov dl, 10     ; X = 10&lt;br /&gt;
                  int 10h        ;Call BIOS procedure to set the cursor position&lt;br /&gt;
        ;Display result message&lt;br /&gt;
                  mov ah, 09h            ;Display string function&lt;br /&gt;
                  mov dx, offset message_res;Pass the starting address of string&lt;br /&gt;
                  int 21h                ;Call DOS to display a message&lt;br /&gt;
&lt;br /&gt;
        ;Convert the two input digits from ASCII codes into binary values&lt;br /&gt;
                                       ;Note: ASCII codes for 0 - 9 are: 30h-39h&lt;br /&gt;
                  and first_num, 0fh   ;”Mask off” the upper 4 bits of the ASCII&lt;br /&gt;
                                       ; code leaving 4 bits of actual value&lt;br /&gt;
                                       ; (i.e., force the high-order four bits&lt;br /&gt;
                                       ;  of first_num to be 0’s and leave the&lt;br /&gt;
                                       ;  lower four bit values as is)&lt;br /&gt;
                                       ; (e.g., the ASCII code for ‘6’ is 36h&lt;br /&gt;
                                       ;  where 36h AND 0fh = 06h (the high-&lt;br /&gt;
                                       ;  order four bits have become 0’s))&lt;br /&gt;
 &lt;br /&gt;
                  and second_num, 0fh  ;Same operation on the second number&lt;br /&gt;
&lt;br /&gt;
        ;Add the two binary numbers&lt;br /&gt;
                  mov al, second_num   ;Copy the value in second_num into&lt;br /&gt;
                                       ; register AL&lt;br /&gt;
                  add al, first_num    ;Add the value in first_num to the value&lt;br /&gt;
                                       ; in register AL (second_num) and place&lt;br /&gt;
                                       ; the result into register AL&lt;br /&gt;
&lt;br /&gt;
        ;Convert the result (the sum) into ASCII codes in the "result" array&lt;br /&gt;
                  cmp al, 9            ;Compare the result (in AL) to 9&lt;br /&gt;
                  ja ten_or_more       ;Jump if (register AL) is above 9 to the&lt;br /&gt;
                                       ; label ten_or_more&lt;br /&gt;
                                       ;Do not jump (continue execution&lt;br /&gt;
                                       ; downward) if register AL is 9 or less&lt;br /&gt;
                  mov result[0], ' '   ;Move the ASCII code for a ‘space’ into&lt;br /&gt;
                                       ; the first byte of the result array&lt;br /&gt;
                                       ; (i.e., the leading digit of the result&lt;br /&gt;
                                       ; will be a ‘space’ character since the&lt;br /&gt;
                                       ; result is 9 or less (requiring only one&lt;br /&gt;
                                       ; digit to express the result))&lt;br /&gt;
                  mov result[1], al    ;Move the numerical result into the&lt;br /&gt;
                                       ; second byte of the result array&lt;br /&gt;
                  or  result[1], 30h   ;Convert the numerical result (in the&lt;br /&gt;
                                       ; second byte of the array) into the&lt;br /&gt;
                                       ; corresponding ASCII code&lt;br /&gt;
                                       ; (e.g., if result[1] = 09h then&lt;br /&gt;
                                       ;  result[1] OR 30h = 39h where 39h is&lt;br /&gt;
                                       ;  ASCII code for a ‘9’)&lt;br /&gt;
                  jmp show_it          ;Jump to the code that calls the DOS&lt;br /&gt;
                                       ; display procedure so as to display the&lt;br /&gt;
                                       ; contents of the result array&lt;br /&gt;
&lt;br /&gt;
     ten_or_more: mov result[0], '1'   ;Move the ASCII code for a ‘1’ into the&lt;br /&gt;
                                       ; first byte of result array (i.e., this&lt;br /&gt;
                                       ; represents a ‘carry’ of 1 – which is&lt;br /&gt;
                                       ; needed because the result is 10 or&lt;br /&gt;
                                       ; more)&lt;br /&gt;
                  sub al, 10           ;Reduce the addition result (in register&lt;br /&gt;
                                       ; AL) by 10 due to carry (a 1 was placed&lt;br /&gt;
                                       ; into the 10’s column so 10 should be&lt;br /&gt;
                                       ; subtracted from the 1’s column)&lt;br /&gt;
                  mov result[1], al    ;Move the low-order digit of the result&lt;br /&gt;
                                       ; to the second byte of the result array&lt;br /&gt;
                  or  result[1], 30h   ;Convert the second byte of the result&lt;br /&gt;
                                       ; into the corresponding ASCII code&lt;br /&gt;
                   &lt;br /&gt;
        ;Display the result&lt;br /&gt;
         show_it: mov ah, 09h            ;Display string function&lt;br /&gt;
                  mov dx, offset result  ;Pass the starting address of string&lt;br /&gt;
                  int 21h                ;Call DOS to display the string&lt;br /&gt;
        ;Set cursor position&lt;br /&gt;
                  mov ah, 02h    ;Set cursor position function&lt;br /&gt;
                  mov bh, 0      ; Display page 0&lt;br /&gt;
                  mov dh, 14     ; Y = 14&lt;br /&gt;
                  mov dl, 10     ; X = 10&lt;br /&gt;
                  int 10h        ;Call BIOS to set the cursor position&lt;br /&gt;
 &lt;br /&gt;
        ;Display quit or continue message&lt;br /&gt;
                  mov ah, 09h            ;Display string function&lt;br /&gt;
                  mov dx, offset message_exit  ;Pass the starting address of the&lt;br /&gt;
                                               ; string to be displayed&lt;br /&gt;
                  int 21h                ;Call DOS to display the string&lt;br /&gt;
&lt;br /&gt;
        ;Get user response&lt;br /&gt;
                  mov ah, 00h    ;Read keyboard function&lt;br /&gt;
                  int 16h        ;Call BIOS (return occurs when key is pressed)&lt;br /&gt;
&lt;br /&gt;
                                 ;AL now contains ASCII code of key pressed&lt;br /&gt;
                  cmp al, 'N'&lt;br /&gt;
                  je quit&lt;br /&gt;
                  cmp al, 'n'&lt;br /&gt;
                  je quit&lt;br /&gt;
                  jmp goofey     ;Jump back to the label goofey if the user&lt;br /&gt;
                                 ; did not press either ‘N’ or ‘n’&lt;br /&gt;
&lt;br /&gt;
            quit: mov ah, 4ch    ;Exit to DOS function&lt;br /&gt;
                  mov al, 0      ; ERRORLEVEL = 0&lt;br /&gt;
                  int 21h        ;Call DOS&lt;br /&gt;
&lt;br /&gt;
           BOZOS_CODE ENDS&lt;br /&gt;
           END START           ;You MUST have a carriage return after START&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/425150/425150/add-2-hex-values-and-display-the-result/</guid>
      <pubDate>Fri, 07 Oct 2011 13:39:07 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>x86 asm with Notepad problem</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/425136/425136/x86-asm-with-notepad-problem/</link>
      <description>Hi.I am learning new x86asm.I'm trying to run this code:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
MOV AH,02	
MOV DL,"!"    	
INT 21h		
MOV AH,04Ch	
MOV AL,00	
INT 21h		
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
I'm saving Exam.asm with notepad in ANSI mod.After this file's extension .asm but file is txt file. &lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/425136/425136/x86-asm-with-notepad-problem/</guid>
      <pubDate>Fri, 07 Oct 2011 09:09:12 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>Code assembles and links but bash rejects it</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/424768/424768/code-assembles-and-links-but-bash-rejects-it/</link>
      <description>I just wrote this code, it assembles fine. I used GAS and it x86_64.&lt;br /&gt;
I linked it like this:&lt;br /&gt;
&lt;br /&gt;
ld -o ./maximum /usr/lib64/crt1.o /usr/lib64/crti.o ./maximum.o -lc&lt;br /&gt;
&lt;br /&gt;
There's no errors. But then I run it and I get this:&lt;br /&gt;
&lt;br /&gt;
bash: ./maximum: No such file or directory&lt;br /&gt;
&lt;br /&gt;
Just to make sure, I ran it and gdb and got the same error.&lt;br /&gt;
&lt;br /&gt;
Here's the code:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
# PURPOSE:      This program finds the maximum number of a
#               set of data items.
#


.section .data

hello_msg:

        .asciz "Hello from GAS :)\\n"

current_data_item_msg:

        .asciz "Current data item #%d: %d\\n"

greatest_data_item:

        .asciz "Greatest data item: %d\\n"

exit_msg:

        .asciz "See ya!!\\n"

debug_1:

        .asciz "Args #: %d\\n"

debug_2:

        .asciz "Mem for args: %d + 8 bytes\\n"

.section .text

.globl main

main:

leaq (%rsp), %rdx                       # need old stack frame to get args

pushq %rbp                              # Create a new stack frame
movq %rsp, %rbp                         # following C runtime rules
pushq %rsi
pushq %rdi
pushq %rbx

movq (%rdx), %rcx                       # Move argc to counter



                pushq %rdx                      # START DEBUG: Print # args
                pushq %rcx

                pushq %rcx
                pushq $debug_1
                call printf

                addq $16, %rsp

                popq %rcx
                popq %rdx                       # END DEBUG




cmpq $2, %rcx                           # if no arguments, goto no_args
jl no_args

decq %rcx
movq %rdx, %rsi
addq $8, %rsi                           # skip the program name, store start of args in rsi

movq %rcx, %rax                         # add enough memory to the stack frame
movq $8, %rbx
mulq %rbx                               # to hold all the args
movq %rax, %rbx
addq $8, %rbx                           # add extra 8 bytes for terminating data item (0)



                pushq %rdx                      # START DEBUG: Print mem needed for args on stack
                pushq %rbx
                pushq %rcx

                subq $8, %rbx

                pushq %rbx
                pushq $debug_2
                call printf

                addq $16, %rsp
                popq %rcx
                popq %rbx
                popq %rdx                       # END DEBUG



movq %rsp, %rdi                         # Make room on stack for args
subq %rbx, %rsp                         # put starting address of args in %rdi

movq $0, %rax                           # Going to store args source index in %rax

#
# Go through argv[ i ] and put every argv on the stack
#
# Or if there are no argvs, then just use random numbers
#

# rcx: decrementing counter on number of args left
# rdi: start of stack space for storing args
# rsi: start of pointers to arg strings
# rax: current arg number

arg_loop_start:

        cmpq $0, %rcx
        je arg_quit

                pushq %rcx

                movq %rax, %r9
                pushq %r9

                pushq 0(%rsi,%rax,8)
                call atoi
                addq $8, %rsp

                popq %r9

                movq %rax, 0(%rdi,%r9,8)        # put current arg in stack 

                movq %r9, %rax

                popq %rcx

        incq %rax
        decq %rcx

no_args:

        movq %rsp, %rdi
        subq $40, %rsp          # Make room for 5 random data items

        pushq $0                # Seed random number gen
        call time
        addq $8, %rsp

        pushq %rax
        call srand
        addq $8, %rsp

        movq $5, %rcx           # Use 5 random data items
        movq $0, %rax

no_args_loop_start:

        cmpq $0, %rcx
        je arg_quit

        movq %rax, %r9

        pushq %r9

        call rand
        addq $1, %rax           # Make sure its not 0

        popq %r9

        movq %rax, 0(%rdi, %r9, 8)

        movq %r9, %rax

        incq %rax
        decq %rcx

arg_quit:

        movq $0, 0(%rdi, %rax, 8)       # Add the terminating zero


pushq $hello_msg
call printf
addq $8, %rsp


movq $0, %rcx           # Put 0 in the data item index
movq (%rdi), %rbx       # Put the first number in ebx as the largest item

start_data_loop:
        movq 0(%rdi, %rcx, 4), %rdx

        pushq %rcx
        pushq %rdx

        pushq %rdx
        pushq %rcx
        pushq $current_data_item_msg
        call printf

        addq $24, %rsp

        popq %rdx
        popq %rcx

        cmpq $0, %rdx
        je data_loop_quit

        cmpq %rdx, %rbx
        jle not_larger

        movq %rdx, %rbx

not_larger:
        incq %rcx

data_loop_quit:

        pushq %rdx
        pushq $greatest_data_item
        call printf

        addq $16, %rsp

        pushq $exit_msg
        call printf

        sub $8, %rsp


popq %rbx               # Destroy the stack frame and exit
popq %rdi
popq %rsi
movq %rbp, %rsp
popq %rbp

ret
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Btw, I'm just starting to learn assembly so I'm guessing this code doesn't look to good :P&lt;br /&gt;
&lt;br /&gt;
In fact, I'm pretty sure I used mulq wrong here:&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;movq %rcx, %rax                         # add enough memory to the stack frame&lt;br /&gt;
movq $8, %rbx&lt;br /&gt;
mulq %rbx  &lt;/strong&gt;                             # to hold all the args&lt;br /&gt;
movq %rax, %rbx&lt;br /&gt;
addq $8, %rbx                           # add extra 8 bytes for terminating data item (0)&lt;br /&gt;
&lt;br /&gt;
Thanks,&lt;br /&gt;
mikfig&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/424768/424768/code-assembles-and-links-but-bash-rejects-it/</guid>
      <pubDate>Wed, 14 Sep 2011 04:24:04 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>Generating Random Numbers</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/423991/423991/generating-random-numbers/</link>
      <description>First of all let me congratulate for this awesome site. It's been a really helpful source for me. &lt;br /&gt;
&lt;br /&gt;
Now, the problem I'm having is that I need to make a sudoku game with assembly on the intel 8086, and I need a way to make random numbers to initialize the board... I was told that using the interruption 1Ah,00 which is used to read system clock counter, such a thing is possible but I need to use DIV to arrange the range of dx between 0 - 9. &lt;br /&gt;
&lt;br /&gt;
If anyone can give me a hand with this I would appreciate it, if you know a better way it would be awesome. &lt;br /&gt;
&lt;br /&gt;
Thank you for your time. &lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/423991/423991/generating-random-numbers/</guid>
      <pubDate>Wed, 08 Jun 2011 11:35:25 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>Recursive function in x86 Assembly</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/423936/423936/recursive-function-in-x86-assembly/</link>
      <description>Hi,&lt;br /&gt;
How can I write that function in x86 assembly?&lt;br /&gt;
I have tried to write it but I could not. &lt;br /&gt;
I am going to call it from a C function.&lt;br /&gt;
&lt;br /&gt;
Thanks.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: Purple;"&gt;int stirling(int n,int k)&lt;br /&gt;
  {&lt;br /&gt;
&lt;br /&gt;
     if((n==0)&amp;amp;&amp;amp;(k==0))&lt;br /&gt;
           return 1;&lt;br /&gt;
&lt;br /&gt;
     else if((n&amp;gt;=1)&amp;amp;&amp;amp;(k&amp;gt;0))&lt;br /&gt;
             return stirling(n-1,k-1)-(n-1)*stirling(n-1,k);&lt;br /&gt;
&lt;br /&gt;
     else if(n&amp;gt;0)&lt;br /&gt;
            return 0;&lt;br /&gt;
&lt;br /&gt;
    return 0;           &lt;br /&gt;
  }&lt;/span&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/423936/423936/recursive-function-in-x86-assembly/</guid>
      <pubDate>Sun, 29 May 2011 21:37:46 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>253 byte PC minesweeper game (complete source code)</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/423491/423491/253-byte-pc-minesweeper-game-complete-source-code/</link>
      <description>I had some spare time so I wrote this up just for fun. I don't know of any 256 byte compos going on right now so I'll just post it here...&lt;br /&gt;
&lt;br /&gt;
Since this forums policy forbids me from posting the compiled version you must make do with only the full source code&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
; Mine - 253 byte minesweeper - written by Chris Mumma - 2011 (public domain)
; inspired by James David Chapman and his 256 byte games (TET/INV/BD3)
; Mr Chapman's games can be found at his website:
; &lt;a href="http://www.users.globalnet.co.uk/~jchap/tvpro256.htm"&gt;http://www.users.globalnet.co.uk/~jchap/tvpro256.htm&lt;/a&gt;
; compile with FASM - &lt;a href="http://flatassembler.net/"&gt;http://flatassembler.net/&lt;/a&gt;
;
; Control with mouse
; Press any key after win/loose to exit game
; Asterisks (*) are mines. If you see one you've lost
;
; Features:
;  40x25 character C0LOR text mode
;  playable with a one button mouse
;  8x8 square board with 8 mines (randomized each game)
;  mouse clicks uncover empty spots with floodfill
;  numbers to indicate nearby mines
;  holding mouse button down while moving the mouse acts like rapid clicks
;  exit game code (press any key after win or loose)
;
; features cut out:
;  all text and user messages
;  flagging mines with right click
;  proper 8-way floodfill
;  game timer
;  adjustable board size
;  mouse driver check`                       
;
; won't run under DosBox as it lacks 100% compatable text mode mouse cursor
; (I understand that. I figure almost no dos games use text mode with a mouse)
; tested and works under windows 7 console (CMD.EXE / NTVDM)
; should run on any 386 based DOS PC but I don't have the resources to do
; extensive testing...

mapSize    equ 8     ; easy mode right? (square maps only)
mineCount  equ 8     ; (16x16 w/40 mines = medium | 24x24 w/90 mines = hard)
mapData    equ heapPtr + 80  ; generated mine map memory offset

org 100h            ; dos .com file program start
    inc ax
    int 10h         ; set 40x25
    int 33h         ; show mouse cursor
;init game map in heap
    mov ah,7            ; set text color
    mov di,mapData - 80
    mov cl,40           ; assume CH = null on entry
    rep stosw           ; line of null (for map clipping)
    mov cl,mapSize
@@: push cx
    mov cl,mapSize      ; square maps only
    mov al,20h          ; empty space marked with space (bar)
    rep stosw
    mov al,0
    mov cl,40-mapSize   ; rest of screen is null
    rep stosw
    pop cx
    loop @B
    mov cl,40
    rep stosw           ; line of null at end of data
;generate mines
    mov di,mapData
    mov cl,mineCount
@@: in ax,40h
    mov bx,mapSize*40   ; size of map buffer in bytes (including nulls)
    xor dx,dx           ; clear DX for DIV
    div bx
    mov bx,dx           ; spot == rand()%total_spots
    shl bx,1            ; force even (word align) address
    mov dx,[di+bx]      ; load map spot
    cmp dl,20h
    jne @B              ; only write in empty space (20h)
    mov byte [di+bx],'*'
;place numbers on map around mines giving hints
    sub bx,82
    call packMineCount  ; NW, N, NE
    add bx,154
    call packMineCount  ; SW, S, SE
    sub bx,82
    call mineCounter    ; E
    sub bx,4
    call mineCounter    ; W
    loop @B
;setup video segment
    push 0B800h
    pop es
;draw board to screen
    xor di,di
    mov ax,7FEh         ; color + ascii char
    mov cl,mapSize
@@: push cx
    mov cl,mapSize
    rep stosw
    pop cx
    add di,80-(mapSize*2)   ; next line down
    loop @B
inputLoop:
    mov ax,3            ; read mouse info
    int 33h
    shr cx,2            ; horz. 0-80 -&amp;gt; 320/4 = 40 chars (80 bytes)
    shr dx,3            ; vert. 0-24 -&amp;gt; 200/8 = 25 chars high
    and bx,bx           ; test buttons
    jz inputLoop
;calc mouse click address
    mov ax,80
    mul dx              ; mul doubles as xor dx,dx later on
    add ax,cx           ; 80*y + x
    mov si,ax           ; si = video and map data offset
;click action
    call stackFill
    lods word [es:si]   ; (lodsw [es:si]) bytecode: db 26h, 0ADh
    cmp al,'*'
    jne @F
winLoose:           ; win or loose brings us here
    xor ax,ax
    int 16h
    ret             ; END OF GAME
; win game test.... if unclicked spaces == mineCount then you win
@@: xor si,si
    mov cx,mapSize*40
wincheck:
    lods word [es:si]   ; lodsw [es:si] (bytecode: db 26h,0ADh)
    cmp al,0FEh         ; still covered?
    jne @F
    inc dx          ; count unclicked spots
@@: loop wincheck
    cmp dl,mineCount    ; all mines accounted for?
    je winLoose
jmp inputLoop

;do horizontal row of three (above or below a mine)
packMineCount:          ; save some bytes
    push cx
    mov cl,3
@@: call mineCounter
    inc bx
    inc bx
    loop @B
    pop cx
ret

;incriment 1 of the 8 spaces around mine (assuming no other mine in it)
mineCounter:
    mov dx,[di+bx]
    and dl,dl           ; game board clipping
    jz @F
    cmp dl,'*'          ; dont change value of mines
    je mineCountDone
    cmp dl,20h
    jne @F
    mov dx,830h
@@: sub dx,0FEFFh
    mov [di+bx],dx      ; and store
mineCountDone:
ret

;4-way flood fill (not full 8 way)
stackFill:
    mov ax,[es:si]      ; load scr char
    cmp al,0FEh         ; don't fill if already revealed/flagged
    jne @F
    mov ax,[si+mapData] ; load map char
    mov [es:si],ax      ; copy to screen
    cmp al,20h          ; stop fill if close to a mine
    jne @F          ; if map char != empty space then ret
    lodsw           ; si+=2
    call stackFill      ; x+1
    add si,78
    call stackFill      ; y+1
    sub si,160
    call stackFill      ; y-1
    add si,78
    call stackFill      ; x-1
    lodsw           ; si+=2
@@: ret

heapPtr:            ; start of game map memory heap

;END OF PROGRAM

&lt;/pre&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/423491/423491/253-byte-pc-minesweeper-game-complete-source-code/</guid>
      <pubDate>Tue, 26 Apr 2011 23:30:56 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>slow floating point on Pentium 4</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/423448/423448/slow-floating-point-on-pentium-4/</link>
      <description>Hi,&lt;br /&gt;
&lt;br /&gt;
I have performance issues with the following code:&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
mulsd %xmm1, %xmm0&lt;br /&gt;
addsd %xmm2, %xmm0&lt;br /&gt;
add 1, %eax&lt;br /&gt;
cmp 10000000, %eax&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
basically: for (i = 0; i &amp;lt; 10000000; ++i) { a = a * b + c; }&lt;br /&gt;
&lt;br /&gt;
when c != 0 it works 20 times faster than when c == 0.0&lt;br /&gt;
&lt;br /&gt;
Does anybody have any ideas on what the problem is?&lt;br /&gt;
&lt;br /&gt;
thanks,&lt;br /&gt;
&lt;br /&gt;
--ckdh&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/423448/423448/slow-floating-point-on-pentium-4/</guid>
      <pubDate>Mon, 25 Apr 2011 06:32:31 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>How can I cuont The number of words in a file ?</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/423394/423394/how-can-i-cuont-the-number-of-words-in-a-file-/</link>
      <description>How can I cuont The number of words in a file ?Using TASM&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/423394/423394/how-can-i-cuont-the-number-of-words-in-a-file-/</guid>
      <pubDate>Sat, 23 Apr 2011 03:02:01 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>Need help with inline assembly in C code</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/423111/423111/need-help-with-inline-assembly-in-c-code/</link>
      <description>Hi everyone, I'm new to this site and hope you might be able to help me out?&lt;br /&gt;
So I've been given an assignment to produce this output:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;% ./hw3b foo
slow foo but foo sure
% ./hw3b XYZ123
slow XYZ123 but XYZ123 sure
% ./hw3b 'stinky junk'
slow stinky junk but stinky junk sure&lt;/pre&gt;&lt;br /&gt;
using asm to insert the word/phrase, and only these libraries: stdlib.h, stdio.h, &amp;amp; string.h.&lt;br /&gt;
I've already done most of the the C coding (shown below) I think, but I'm stuck on the asm assembler code insertion.&lt;br /&gt;
&lt;pre class="sourcecode"&gt;#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
 
char word[] = "here and there";
int sz;
int wordsz;
char *arg;
char *result;
 
int main(int argc, char* argv[]) {
   if (argc != 2) {
     printf("Usage: %s takes one string argument.\n", argv[0]);
     exit(1);
   }
 
   sz = strlen(argv[1]) + 1;
   arg = malloc(sz);
   strcpy(arg, argv[1]);
   wordsz = strlen(word) + 1;
   result = malloc(sz * wordsz);
 
   __asm__("\n\
     \*In here will be a loop which will use iter
       to iterate one char (byte) at a time.
       When it comes upon a space char it will exit
       to the print statement, but when it comes
       upon a newline, it will ret and exit*\
");
   //I'm thinkin of something like this, where temp_save is there
   //to save the index of the beginning of the last word to
   //provide a range ([temp_save,iter]) for strncpy()
   //So essentially this will copy the correct range out of word
   //and append it (followed by the keyword arg) onto result
   strcat(result,"%s %s",strncpy(result,word+temp_save,iter),arg);
   temp_save=iter;
 
   __asm__("\n\
     \*If newline delimiter not reached, return to
       previous loop*\
");
   printf("%s\n", result);
   return 0;
}&lt;/pre&gt;&lt;br /&gt;
&lt;hr /&gt;&lt;br /&gt;
Herein lies my issue: how can I detect a space (' ') char using assembly?&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/423111/423111/need-help-with-inline-assembly-in-c-code/</guid>
      <pubDate>Thu, 07 Apr 2011 14:41:39 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>Linked List in ASM</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/423068/423068/linked-list-in-asm/</link>
      <description>I want to write a simple linked list program with ASM .&lt;br /&gt;
Here's the code which I have tried to write(presently only for single digit numbers) ! However,it works only for 3 numbers and that too has sometimes some errors. I am new to assembly language.&lt;br /&gt;
So please help me as to what I am supposed to do,as I am in fix !&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;.model small

.data
	m1 db 10,13,'Enter Data :: $'
    m2 db 10,13,'Continue ?? $'
    head dw 0
.code
	mov ax,@data
	mov ds,ax

    mov bx,1
    mov ah,48h
    int 21h

    mov head,ax

    mov dx,offset m1
    mov ah,09h
    int 21h
    mov ah,01h
    int 21h
    xor ah,ah
    mov bx,head
    mov [bx],ax
    mov di,head

    mov dx,offset m2
    mov ah,09h
    int 21h
    mov ah,01h
    int 21h
    cmp al,'y'
    je loop1
    cmp al,'Y'
    je loop1
    jmp below
       
loop1:
    mov bx,1
    mov ah,48h
    int 21h

    xor si,si
    mov [di+2],ax
    xor di,di
    mov si,ax
    mov dx,offset m1
    mov ah,09h
    int 21h
    mov ah,01h
    int 21h
    xor ah,ah
    mov word ptr [si],ax
    mov di,si
    
    mov dx,offset m2
    mov ah,09h
    int 21h
    mov ah,01h
    int 21h
    cmp al,'y'
    je loop1
    cmp al,'Y'
    je loop1

below:
    mov word ptr [di+2],0
    
disp:
    mov ah,02h
    mov dx,10
    int 21h
    mov dx,13
    int 21h
    mov bx,head
    mov ah,02h
    mov dx,[bx]
    int 21h

lp:
    mov ah,02h
    add bx,2
    mov dx,word ptr [bx]
    int 21h
    cmp word ptr [bx+2],0
    jnz lp

exit:
    mov ah,4ch
    int 21h

end&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/423068/423068/linked-list-in-asm/</guid>
      <pubDate>Thu, 07 Apr 2011 02:58:59 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>Manually changing SP to prevent stack overflow</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/423002/423002/manually-changing-sp-to-prevent-stack-overflow/</link>
      <description>I'm still working on my game project (a text-based dungeon crawl in the tradition of several DOS-based BBS door games), although it's coming along further.  I ran into a design problem, though, and I'd like some input on my stop-gap solution.&lt;br /&gt;
&lt;br /&gt;
With my current approach the stack will eventually overflow if the user dies and either starts a new game or loads from a previous save several times in a single program execution.  My tentative fix is to save SP right before the main loop that calls all other branching functions, and in the event the player restarts I restore that SP value and jump back to the beginning of that main loop.  Here are some code snippets, TASM syntax:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;        public  SP_STATE, GAME_RESET
SP_STATE        dw      0               ;Stack Pointer state stored for game resetting
                                        ; to keep stack from overflowing.

GAME_RESET      dw      DrawMenu        ;Offset of DrawMenu for resetting game.
.
.
.

        public  TextDungeon
        extrn   ReadByte:proc, ClearScreen:proc, WriteString:proc
        extrn   SendCRLF:proc, GotoXY:proc, WriteChar:proc
        extrn   RandomMonster:proc, ResetChar:proc

TextDungeon     proc
        push    ax
        push    bx
        push    dx    
        mov     [SP_STATE],sp           ;Save SP to SP_STATE for later reset

DrawMenu:
        call    ClearScreen
        xor     dx,dx
        call    GotoXY                  ;Put cursor at 0,0 (top left)
        mov     dx,[CurrentMenu]
        call    WriteString             ;Draw menu and prompt
        lea     dx,[MenuPrompt]
        call    WriteString
.
.
.
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
And here is the current SP resetting procedure:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
        public  RenewGame
        extrn   ClearScreen:proc, ChangeName:proc, TextDungeon:proc
        extrn   ResetChar:proc
.data
        extrn   SP_STATE:word, GAME_RESET:word

.code
RenewGame       proc
        call    ClearScreen
        call    ResetChar
        call    ChangeName
        mov     ax,[GAME_RESET]
        mov     sp,[SP_STATE]
        jmp     ax                      ;Jump to TextDungeon DrawMenu label.
        
        mov     ax,4C99h                ;Should never be reached but gives error
        int     21h                     ; and exits if it happens...

RenewGame       endp&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
I've read repeatedly that SP should never be modified directly unless you know exactly what you're doing, given that a system interrupt can occur in the middle of the process and bring the whole thing to an ugly, grinding halt.  I've done my best to ensure that the IP change happens immediately after the SP change, which seems to me like it should minimize the chance of a problem down to the smallest it can get.&lt;br /&gt;
&lt;br /&gt;
Is this a good way to do things or should I suck it up and fix my short-sighted design?</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/423002/423002/manually-changing-sp-to-prevent-stack-overflow/</guid>
      <pubDate>Mon, 04 Apr 2011 11:55:48 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>MATLAB Assignment Help</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/422120/422120/matlab-assignment-help/</link>
      <description>I need to find&lt;br /&gt;
1. List the materials in your database that have Young’s modulus &amp;gt; 100 GPa.&lt;br /&gt;
2. List the materials that cost &amp;lt; $20,000/tonne.&lt;br /&gt;
3. List the materials that have a density &amp;lt; 6x103 kg/m3&lt;br /&gt;
4. Now combine these three searches together that list the materials that have Young’s modulus &amp;gt; 100&lt;br /&gt;
GPa, cost &amp;lt; $20,000/tonne and density &amp;lt; 6 x 103 kg/m3.&lt;br /&gt;
5. As a final exercise with this data, count the number of metals that would be considered precious (i.e.&lt;br /&gt;
worth more than $500,000/tonne).&lt;br /&gt;
&lt;br /&gt;
Here is what I have so far ( I have already inputed the data ), I am having troubles with converting d to the element names. I tried using char(d) but it wouldn't work&lt;br /&gt;
&lt;br /&gt;
x = [element(1:9).youngs_modulus]&amp;gt;100;&lt;br /&gt;
f = num2str(x);&lt;br /&gt;
d = strfind(f,'1')&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/422120/422120/matlab-assignment-help/</guid>
      <pubDate>Wed, 02 Mar 2011 09:32:54 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
    <item>
      <title>HELP! Number Conversion Problem</title>
      <link>http://www.programmersheaven.com/mb/x86_asm/422090/422090/help-number-conversion-problem/</link>
      <description>Hey guys!  I am just getting started in assembly language and my head hurts from staring at this problem.  I'll paste in the program requirements, then my program and show where I am stuck...any help would be appreciated..I have a test in 7 hrs!!&lt;br /&gt;
&lt;br /&gt;
Problem:&lt;br /&gt;
&lt;br /&gt;
Number Conversion&lt;br /&gt;
&lt;br /&gt;
In this lab, you will be converting a sequence of characters read from the console into a simple unsigned integer number.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You will need four sections in your program:&lt;br /&gt;
Part 1 - Sign on&lt;br /&gt;
&lt;br /&gt;
Print out a simple program message with the name of your program and a prompt for the user to enter an integer number. We will ask the user to type in at most four digits only. You may assume (never a good idea in real life) that the user is smart, and only enters what you ask: four or less digits followed by the Enter key. (No error checking is needed beyond this).&lt;br /&gt;
&lt;br /&gt;
Part 2 - Getting user data&lt;br /&gt;
&lt;br /&gt;
Read the user input using the get_kb routine defined in the C library (include the asm_io line for this to work). This routine returns a single character in the EAX register - only the low 8 bits (AL) are of interest. This routine does not echo the character the user typed on the screen - if you want that to happen, you will need to use the print_char routine to make that happen.&lt;br /&gt;
&lt;br /&gt;
Part 3 - Converting the characters to numbers&lt;br /&gt;
&lt;br /&gt;
The character you get from the user ends up in the AL register as a binary number that is the ASCII code for the key pressed. You will need to convert this code into the right numerical value (look at the ASCII code table and you will see that the digits are in order starting at a code of 30h. So to convert the code for the digit 3, we could subtract 30h from that code and we would get a binary value of 3. Sound right?&lt;br /&gt;
&lt;br /&gt;
Think about how you would do the rest of the conversion. You will see the user’s digits left to right. How can you form the answer?&lt;br /&gt;
&lt;br /&gt;
You will probably need to look up the instruction to multiply an integer by another integer to figure this out (Try this: oldnum = oldnum * 10 + new num. That should get you started)&lt;br /&gt;
Part 4 - Print out the answer&lt;br /&gt;
&lt;br /&gt;
Once you have the number converted, use the print_int routine from your library to display the result. You should see the number the user typed in.&lt;br /&gt;
------------------------------------&lt;br /&gt;
My code so far:&lt;br /&gt;
&lt;br /&gt;
_asm_main:&lt;br /&gt;
            enter   0,0&lt;br /&gt;
            mov     eax, message        &lt;br /&gt;
            call    print_string        ; display startup message&lt;br /&gt;
            call    print_nl&lt;br /&gt;
            call    print_nl&lt;br /&gt;
            &lt;br /&gt;
            mov     eax, prompt         ; prompt user for number&lt;br /&gt;
            call    print_string        &lt;br /&gt;
            call    print_nl&lt;br /&gt;
&lt;br /&gt;
number_entry:&lt;br /&gt;
            call    get_kb              ; read keyboard input&lt;br /&gt;
            call    print_char          ; displays first digit&lt;br /&gt;
            cmp     al, 0dh             ; end of user input?&lt;br /&gt;
            jne     number_entry        ; if not, loop again&lt;br /&gt;
            sub     al, 30h             ; subtracts hex 0 from hex input&lt;br /&gt;
            mov     bl, al              ; copies what user input to memory&lt;br /&gt;
&lt;br /&gt;
            call    print_nl&lt;br /&gt;
            mov     eax, message2&lt;br /&gt;
            call    print_string    &lt;br /&gt;
&lt;br /&gt;
convert_number: &lt;br /&gt;
&lt;br /&gt;
-------------------------------------&lt;br /&gt;
&lt;br /&gt;
so I can input, and echo user input.  What's not making sense is how I deal with what is put into the AL register and how I manipulate it bit by bit.  Also I vaguely recall reading that an ASCII character is a byte long so when the character that is input by the user is saved to AL is it a byte long?  SO CONFUSED!!!  please help &lt;img src="http://www.programmersheaven.com/images/Community/frown.gif" width="15" height="15" alt="" /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/x86_asm/422090/422090/help-number-conversion-problem/</guid>
      <pubDate>Tue, 01 Mar 2011 09:41:23 -0800</pubDate>
      <category>x86 Assembly</category>
    </item>
  </channel>
</rss>
