<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.wcipeg.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Judge%3AHelp%2Faplusb.asm</id>
		<title>Judge:Help/aplusb.asm - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.wcipeg.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Judge%3AHelp%2Faplusb.asm"/>
		<link rel="alternate" type="text/html" href="http://www.wcipeg.com/wiki/index.php?title=Judge:Help/aplusb.asm&amp;action=history"/>
		<updated>2026-05-10T05:06:05Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.25.2</generator>

	<entry>
		<id>http://www.wcipeg.com/wiki/index.php?title=Judge:Help/aplusb.asm&amp;diff=1424&amp;oldid=prev</id>
		<title>Brian: Created page with &quot;&lt;syntaxhighlight lang=&quot;asm&quot;&gt; %macro  getchar 1                       ;&quot;getchar()&quot;         cmp     byte [esi],0         jnz     .getchar_bottom         push    eax         push   ...&quot;</title>
		<link rel="alternate" type="text/html" href="http://www.wcipeg.com/wiki/index.php?title=Judge:Help/aplusb.asm&amp;diff=1424&amp;oldid=prev"/>
				<updated>2011-10-19T00:33:49Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;syntaxhighlight lang=&amp;quot;asm&amp;quot;&amp;gt; %macro  getchar 1                       ;&amp;quot;getchar()&amp;quot;         cmp     byte [esi],0         jnz     .getchar_bottom         push    eax         push   ...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;asm&amp;quot;&amp;gt;&lt;br /&gt;
%macro  getchar 1                       ;&amp;quot;getchar()&amp;quot;&lt;br /&gt;
        cmp     byte [esi],0&lt;br /&gt;
        jnz     .getchar_bottom&lt;br /&gt;
        push    eax&lt;br /&gt;
        push    ebx&lt;br /&gt;
        push    ecx&lt;br /&gt;
        push    edx&lt;br /&gt;
        mov     eax,3                   ;sys_read&lt;br /&gt;
        mov     ebx,0                   ;stdin&lt;br /&gt;
        mov     ecx,esi                 ;buf&lt;br /&gt;
        mov     edx,100                 ;#bytes&lt;br /&gt;
        int     0x80&lt;br /&gt;
        add     esi,eax                 ;just after last byte&lt;br /&gt;
        mov     byte [esi],0            ;so we remember&lt;br /&gt;
        sub     esi,eax&lt;br /&gt;
        pop     edx&lt;br /&gt;
        pop     ecx&lt;br /&gt;
        pop     ebx&lt;br /&gt;
        pop     eax&lt;br /&gt;
.getchar_bottom:&lt;br /&gt;
        mov     %1,byte [esi]&lt;br /&gt;
        inc     esi&lt;br /&gt;
%endmacro&lt;br /&gt;
%macro  putchar 1&lt;br /&gt;
        mov     byte [edi],%1&lt;br /&gt;
        inc     edi&lt;br /&gt;
%endmacro&lt;br /&gt;
section .text&lt;br /&gt;
        global _start                   ;must be declared for linker (ld)&lt;br /&gt;
_start:&lt;br /&gt;
        mov     esi,indata&lt;br /&gt;
        mov     byte [esi],0&lt;br /&gt;
        mov     edi,outdata             ;output pointer&lt;br /&gt;
        call    getint&lt;br /&gt;
        mov     ebx,eax&lt;br /&gt;
        call    getint&lt;br /&gt;
        add     eax,ebx&lt;br /&gt;
        call    putint&lt;br /&gt;
        putchar 10                      ;&amp;quot;printf(&amp;quot;\n&amp;quot;)&amp;quot;&lt;br /&gt;
        mov     eax,4                   ;sys_write&lt;br /&gt;
        mov     ebx,1                   ;stdout&lt;br /&gt;
        mov     ecx,outdata&lt;br /&gt;
        mov     edx,edi&lt;br /&gt;
        sub     edx,outdata             ;#bytes&lt;br /&gt;
        int     0x80                    ;&amp;quot;write(stdout,outdata,edi-outdata)&amp;quot;&lt;br /&gt;
        mov     eax,1                   ;sys_exit&lt;br /&gt;
        mov     ebx,0                   ;success&lt;br /&gt;
        int     0x80                    ;&amp;quot;exit(0)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
getint:                                 ;&amp;quot;scanf(&amp;quot;%d&amp;quot;,&amp;amp;eax)&amp;quot;&lt;br /&gt;
        mov     eax,0&lt;br /&gt;
        push    ebx&lt;br /&gt;
        mov     ebx,0&lt;br /&gt;
        mov     ecx,0                   ;negative or not&lt;br /&gt;
getint_eatwhite:&lt;br /&gt;
        getchar bl&lt;br /&gt;
        cmp     ebx,32&lt;br /&gt;
        jg      getint_top&lt;br /&gt;
        jmp     getint_eatwhite&lt;br /&gt;
getint_top:&lt;br /&gt;
        cmp     ebx,'-'&lt;br /&gt;
        jnz     getint_notminus&lt;br /&gt;
        getchar bl&lt;br /&gt;
        mov     ecx,1&lt;br /&gt;
getint_notminus:&lt;br /&gt;
        sub     ebx,'0'&lt;br /&gt;
        lea     eax,[4*eax+eax]         ;eax *= 5&lt;br /&gt;
        shl     eax,1                   ;eax *= 2&lt;br /&gt;
        add     eax,ebx&lt;br /&gt;
        getchar bl&lt;br /&gt;
        cmp     ebx,32&lt;br /&gt;
        jle     getint_bottom&lt;br /&gt;
        jmp     getint_top&lt;br /&gt;
getint_bottom:&lt;br /&gt;
        cmp     ecx,0&lt;br /&gt;
        jz      getint_return&lt;br /&gt;
        neg     eax&lt;br /&gt;
getint_return:&lt;br /&gt;
        pop     ebx&lt;br /&gt;
        ret&lt;br /&gt;
&lt;br /&gt;
putint:                                 ;&amp;quot;printf(&amp;quot;%d&amp;quot;,eax)&amp;quot;&lt;br /&gt;
        cmp     eax,0&lt;br /&gt;
        jge     putint_nonnegative&lt;br /&gt;
        neg     eax&lt;br /&gt;
        putchar 45                      ;minus sign&lt;br /&gt;
putint_nonnegative:&lt;br /&gt;
        cmp     eax,10&lt;br /&gt;
        jl      putint_base&lt;br /&gt;
        mov     edx,0&lt;br /&gt;
        mov     ebx,10&lt;br /&gt;
        div     ebx&lt;br /&gt;
        push    edx&lt;br /&gt;
        call    putint&lt;br /&gt;
        pop     edx&lt;br /&gt;
        add     edx,'0'&lt;br /&gt;
        putchar dl&lt;br /&gt;
        ret&lt;br /&gt;
putint_base:&lt;br /&gt;
        add     eax,'0'&lt;br /&gt;
        putchar al&lt;br /&gt;
        ret&lt;br /&gt;
read:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
section .bss&lt;br /&gt;
indata  resb    20&lt;br /&gt;
outdata resb    20&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Brian</name></author>	</entry>

	</feed>