Programming in Assembly Langauge

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 4500 Views - Last Post: 18 August 2010 - 08:08 AM

#1 markmeplease  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 17
  • Joined: 10-February 10

Programming in Assembly Langauge

Posted 23 July 2010 - 11:40 PM

Hi folks,

I'm having troubles in programming in assembly language, this is my question, How to make a program and add four (4) numbers, (the 4 numbers will be inputted by the user), in assembly language? I only know adding two numbers by user input, Thank you and more power...

-this is my code in adding two numbers.
#make_COM#

; COM file is loaded at CS:0100h
ORG 100h

include 'emu8086.inc'

LEA SI,msg1
CALL PRINT_STRING
CALL scan_num
mov ax,cx

putc 13
putc 10

LEA SI,msg2
CALL PRINT_STRING
CALL scan_num
mov bx,cx

putc 13
putc 10

JMP calc

back: JMP stop

calc:
ADD ax, bx

Print "The sum is: "
CALL print_num
putc 10
putc 13

JMP back

stop:

RET

msg1 DB 'Enter the first number: ',0
msg2 DB 'Enter the second number: ',0

DEFINE_SCAN_NUM
DEFINE_PRINT_STRING
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS


END



Edited by macosxnerd101: Please, :code:.

Is This A Good Question/Topic? 0
  • +

Replies To: Programming in Assembly Langauge

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10694
  • View blog
  • Posts: 39,785
  • Joined: 27-December 08

Re: Programming in Assembly Langauge

Posted 24 July 2010 - 05:47 AM

Moved to Assembly. :)
Was This Post Helpful? 0
  • +
  • -

#3 Crunch  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 139
  • View blog
  • Posts: 1,222
  • Joined: 28-July 09

Re: Programming in Assembly Langauge

Posted 24 July 2010 - 06:30 AM

what's the assembler you are using ?
Was This Post Helpful? 0
  • +
  • -

#4 markmeplease  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 17
  • Joined: 10-February 10

Re: Programming in Assembly Langauge

Posted 25 July 2010 - 12:40 AM

@macosxnerd101:

Thanks for the reply and for the editing you made, I really don't know what is the proper format of posting a code, I'm very new here, Hmmmmn, but regarding to your post, what do you mean by "Moved to Assembly."?

Thanks.... :smile2:

@Crunch:

I am using " MicroAsm, Micro Assembler IDE "...
Was This Post Helpful? 0
  • +
  • -

#5 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5365
  • View blog
  • Posts: 27,328
  • Joined: 10-May 07

Re: Programming in Assembly Langauge

Posted 25 July 2010 - 12:55 AM

View Postmarkmeplease, on 25 July 2010 - 01:40 AM, said:

@macosxnerd101:

Thanks for the reply and for the editing you made, I really don't know what is the proper format of posting a code, I'm very new here, Hmmmmn, but regarding to your post, what do you mean by "Moved to Assembly."?

He means he moved the topic to the assembly sub forum, where it should be posted.
Was This Post Helpful? 0
  • +
  • -

#6 markmeplease  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 17
  • Joined: 10-February 10

Re: Programming in Assembly Langauge

Posted 25 July 2010 - 02:55 AM

Oppz...LOL... thanks no2pencil ... Now I know... :balloon:
Was This Post Helpful? 0
  • +
  • -

#7 Krishs  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 23
  • View blog
  • Posts: 105
  • Joined: 06-April 10

Re: Programming in Assembly Langauge

Posted 25 July 2010 - 04:24 AM

well rather you can use memory locations to store four integers in your program data section , and use them in your code .
I am not aware of MicroAsm so i can just show you some code that will work with nasm

to declare variables use

first_no dw 0 ;;; assuming you like to program for 8086
secnd_no dw 0
thirs_no dw 0
forth_no dw 0

while after call to scan_num you can transfer value in reg to mem loc much like
mov byte ptr [first_no] , cx

now you can get this in your progrm similar way and calculate with it.
Was This Post Helpful? 0
  • +
  • -

#8 markmeplease  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 17
  • Joined: 10-February 10

Re: Programming in Assembly Langauge

Posted 25 July 2010 - 04:38 AM

@Krishs:

:no: Oppzz..I'm not familiar with nasm and in other asm compiler , "just starting in assembly" but, anyway, Thanks for the idea...

:balloon:
Was This Post Helpful? 0
  • +
  • -

#9 Krishs  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 23
  • View blog
  • Posts: 105
  • Joined: 06-April 10

Re: Programming in Assembly Langauge

Posted 25 July 2010 - 06:42 AM

glad to help you markmeplease.
sorry for one misunderstanding , <_<
the code
mov byte ptr [first_no] , cx

actually works with masm or tasm . nasm has little bit different syntax for accessing memory.

BTW if you have just started programming assembly then grabbing the basic things on language will make you comfortable with any assembler on x86. so don't worry about other assemblers :)
Was This Post Helpful? 0
  • +
  • -

#10 markmeplease  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 17
  • Joined: 10-February 10

Re: Programming in Assembly Langauge

Posted 25 July 2010 - 06:17 PM

View PostKrishs, on 25 July 2010 - 08:42 PM, said:

glad to help you markmeplease.
sorry for one misunderstanding , <_<
the code
mov byte ptr [first_no] , cx

actually works with masm or tasm . nasm has little bit different syntax for accessing memory.

BTW if you have just started programming assembly then grabbing the basic things on language will make you comfortable with any assembler on x86. so don't worry about other assemblers :)



-Thank you very much Krishs, anyway, just downloaded the NASM and MASM32 Editor, can you tell me what are the difference??? or what is good ASM compiler that should i use??? because I am really confuse if should I use that or this... thanks a lot...

I am learning the assembler for more one month already.... So, that is why I don't know how to program in assembly... I only have little knowledge .... so, thanks for the help...
Was This Post Helpful? 0
  • +
  • -

#11 Krishs  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 23
  • View blog
  • Posts: 105
  • Joined: 06-April 10

Re: Programming in Assembly Langauge

Posted 26 July 2010 - 02:19 AM

Quote

just downloaded the NASM and MASM32 Editor, can you tell me what are the difference??? or what is good ASM compiler that should i use??? because I am really confuse if should I use that or this...


Actually depends what you r going to achieve.if you r doing programming on windows y can use masm32 as a good choice.But many prefer to use nasm as it is cross platform available , so you can use it on windows as well linux and any BSD series os.

If you go for difference , there is none except in syntax and features offered by them. so there is nothing to worry about difference between them.

But as you are starter , i don't recommend you to go program for windows with masm32 but instead use NASM with easy syntax. as well there is a good tutorial I found on internet apul carter book for beginners . try it a very informative. :)
Was This Post Helpful? 0
  • +
  • -

#12 markmeplease  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 17
  • Joined: 10-February 10

Re: Programming in Assembly Langauge

Posted 26 July 2010 - 03:16 AM

View PostKrishs, on 26 July 2010 - 04:19 PM, said:

Quote

just downloaded the NASM and MASM32 Editor, can you tell me what are the difference??? or what is good ASM compiler that should i use??? because I am really confuse if should I use that or this...


Actually depends what you r going to achieve.if you r doing programming on windows y can use masm32 as a good choice.But many prefer to use nasm as it is cross platform available , so you can use it on windows as well linux and any BSD series os.

If you go for difference , there is none except in syntax and features offered by them. so there is nothing to worry about difference between them.

But as you are starter , i don't recommend you to go program for windows with masm32 but instead use NASM with easy syntax. as well there is a good tutorial I found on internet apul carter book for beginners . try it a very informative. :)



thank you very mush Krishs, this is a big help... I'll study this tutorial... thanks a lot... :bananaman:

This post has been edited by markmeplease: 26 July 2010 - 03:17 AM

Was This Post Helpful? 0
  • +
  • -

#13 markmeplease  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 17
  • Joined: 10-February 10

Re: Programming in Assembly Langauge

Posted 26 July 2010 - 03:30 AM

What's wrong with this code??? :wacko:

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#14 GenHornet18  Icon User is offline

  • Darken the Radar

Reputation: 36
  • View blog
  • Posts: 629
  • Joined: 19-October 09

Re: Programming in Assembly Langauge

Posted 26 July 2010 - 04:34 PM

Read the error messages, they're fairly precise here. The operands are of different sizes, (CX = 16 bit (register), first_no = 8 bit (memory)) you have to match them up. I haven't checked over your code, but if you don't need the top/bottom of CX then use CH/CL. If you need CX then
;change
first_no db 0 ;8 bit
;to
first_no dw 0 ;16 bit



This is fairly basic assembly, you should get to know your platform/registers fully before you run into it.
Was This Post Helpful? 0
  • +
  • -

#15 markmeplease  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 17
  • Joined: 10-February 10

Re: Programming in Assembly Langauge

Posted 27 July 2010 - 06:38 PM

View PostGenHornet18, on 27 July 2010 - 06:34 AM, said:

Read the error messages, they're fairly precise here. The operands are of different sizes, (CX = 16 bit (register), first_no = 8 bit (memory)) you have to match them up. I haven't checked over your code, but if you don't need the top/bottom of CX then use CH/CL. If you need CX then
;change
first_no db 0 ;8 bit
;to
first_no dw 0 ;16 bit



This is fairly basic assembly, you should get to know your platform/registers fully before you run into it.



Opz. sorry, Hmmmn... Just starting in assembly, so I'm not familiar with terms and errors and codes/syntax actually... I asked my instructor about my codes and the codes I have used given in this post, but, He said that this codes/syntax
 first_no	dw	0 ;declarations 
 second_no	dw	0
 third_no	dw	0
 forth_no	dw	0

mov byte ptr [first_no] , cx....


are wrong... :( :wacko:

please teach, or can you please make a sample program in adding 4 numbers... so that, I will have idea on how to do it... thanks... :yes:

This post has been edited by markmeplease: 27 July 2010 - 06:40 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2