Starting assembly language in assembler ?

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

36 Replies - 3269 Views - Last Post: 04 August 2018 - 12:11 PM

#31 sunshine33   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 139
  • Joined: 15-September 17

Re: Starting assembly language in assembler ?

Posted 02 August 2018 - 02:07 PM

I am trying to convert this C code to assembly language ,
Can somebody please tell me which platform is easiest to find help with ?


#include <stdio.h>
int main()
{
    int firstNumber, secondNumber, sumOfTwoNumbers;
    
    printf("Enter two integers: ");

    // Two integers entered by user is stored using scanf() function
    scanf("%d %d", &firstNumber, &secondNumber);

    // sum of two numbers in stored in variable sumOfTwoNumbers
    sumOfTwoNumbers = firstNumber + secondNumber;

    // Displays sum      
    printf("%d + %d = %d", firstNumber, secondNumber, sumOfTwoNumbers);

    return 0;
}



Linux

section .text

global _start               ;must be declared for using gcc

_start:                     ;tell linker entry point

    mov     eax, '3'
    sub     eax, '0'
    mov     ebx, '4'
    sub     ebx, '0'
    add     eax, ebx
    add     eax, '0'

    mov     [sum], eax

    mov     ecx, msg 
    mov     edx, len
    mov     ebx, 1          ;file descriptor (stdout)
    mov     eax, 4          ;system call number (sys_write)
    int     0x80            ;call kernel

    mov     ecx, sum

    mov     edx, 1
    mov     ebx, 1          ;file descriptor (stdout)
    mov     eax, 4          ;system call number (sys_write)
    int     0x80            ;call kernel

    mov     eax, 1          ;system call number (sys_exit)
    int     0x80            ;call kernel


section .data

    msg     db              "The sum is:", 0xA,0xD 

    len equ $ - msg   

    segment .bss

    sum resb 1





MS DOS

.model small

.data
 max_temp DB 92h       
 min_temp DB 52h
 avg_temp DB ?
.code
.startup

 mov ax,@data          
 mov ds,ax
 mov al, max_temp      
 add al, min_temp      
 mov ah, 00h           
 adc ah, 00h           
 mov bl, 02h          
 div bl               
 mov avg_temp, al     
.exit
end



MASM32

.386
.model flat ,stdcall
OPTION CASEMAP:NONE

include masm32.inc
include kernel32.inc
includelib kernel32.lib
includelib masm32.lib

.DATA
MasgName db "Enter the NUmber   ",00ah,00dh

.DATA?
num db 2 dup (?)

.code
start:

invoke StdOut ,addr MasgName

; Get 1st number
invoke StdIn ,addr num,10
; eax = length
 mov [num+ eax-2 ], 0   ; Set terminator
invoke StripLF,ADDR num      
; Now convert ASCIIz number to decimal
invoke atodw , addr num
mov ebx, eax ; Move number from eax to ebx

;_____________
invoke StdOut ,addr MasgName
; Get 2nd number
invoke StdIn ,addr num,10
; eax = length
mov [num+ eax-2 ], 0  ; Set terminator
invoke StripLF,ADDR num    


; Now convert ASCIIz number to decimal
invoke atodw , addr num
        ; eax is 2nd number

add eax,ebx
         
invoke dwtoa, eax,addr num
invoke StdOut ,addr num
invoke StdIn ,addr num,10
invoke ExitProcess,0
end start


Was This Post Helpful? 0
  • +
  • -

#32 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15314
  • View blog
  • Posts: 61,413
  • Joined: 12-June 08

Re: Starting assembly language in assembler ?

Posted 02 August 2018 - 02:17 PM

Quote

Can somebody please tell me which platform is easiest to find help with ?

Please explain this.

.. wait, what? Why are you regurgitating the same question from four months ago?
Was This Post Helpful? 0
  • +
  • -

#33 sunshine33   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 139
  • Joined: 15-September 17

Re: Starting assembly language in assembler ?

Posted 02 August 2018 - 02:24 PM

Which Operating system specific Assembly language has more resources available to learn online ?
Linux , MS DOS or MASM32

?
Was This Post Helpful? 0
  • +
  • -

#34 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15314
  • View blog
  • Posts: 61,413
  • Joined: 12-June 08

Re: Starting assembly language in assembler ?

Posted 02 August 2018 - 02:27 PM

That was already answered as best as someone could in the post right after that.

I believe the more important option was to just pick one and do _something_.
Was This Post Helpful? 0
  • +
  • -

#35 sunshine33   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 139
  • Joined: 15-September 17

Re: Starting assembly language in assembler ?

Posted 02 August 2018 - 02:29 PM

Maybe i should stay with the Linux version of the Assembly language .
Thanks
Was This Post Helpful? 0
  • +
  • -

#36 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15314
  • View blog
  • Posts: 61,413
  • Joined: 12-June 08

Re: Starting assembly language in assembler ?

Posted 02 August 2018 - 02:31 PM

Do what you will, but I urge you to do _something_. No sense in frittering away four months because you opt to not act on a nebulous question.
Was This Post Helpful? 0
  • +
  • -

#37 turboscrew   User is offline

  • D.I.C Lover
  • member icon

Reputation: 171
  • View blog
  • Posts: 1,113
  • Joined: 03-April 12

Re: Starting assembly language in assembler ?

Posted 04 August 2018 - 12:11 PM

If you decide to go with Linux, this might be of help...
https://docs.oracle....77/817-5477.pdf

It's really for Solaris (Unix-like OS for Sun machines), but is pretty good for Linux too. It's basically manual of AT&T syntax x86 assembly.

This might help with getting into 64-bit code...
https://cs.brown.edu..._cheatsheet.pdf

This post has been edited by turboscrew: 04 August 2018 - 12:36 PM

Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3