• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Asembly Input/Output...

tdktank59

Gawd
Joined
Jan 23, 2007
Messages
590
So im trying to write a script for class on how to take a users input (to be exact 4 inputs)...

year1, year2, year3, year4

while each get assigned 1 number of the year (2004 for example would be 2, 0 ,0, 4)

Then I need to output it as well... (after doing a bit of math to convert the 4 digits to the whole 2004 again.)

Im not looking for the answer to do the whole thing just the commands to get the input and how to set it to a varible. I have no clue where to start... Trying to read our book is confusing as hell and I have yet to find a good resource online.

(BTW I would ask my teacher but hes a dick and wont give us an answer since we are #1 our partners #2 other people are #3 book is in there somewhere and he is last... Yet when in class he barely goes over it either...)

Thanks for any help you can give me.

EDIT: Forgot to say we are at the basics of assembly so no macros, or calling any libraries... things like push, pop, mov, add, mul, div, idiv etc... The basics...
 
wait, he didn't even teach you how to do console input?

Or did he, and you just don't get it?

What assembler / platform are you working on? (From what you list I assume x86?)
 
Sorta... He goes over stuff in class but he is never very clear about anything... So in other words I probably did not get it...

Yes Intel x86 masm not sure if we can even call a subroutine...
 
Are you coding under DOS or some other operating system?

If it's DOS, look up Interrupt 21h / Function 0Ah. Buffered input.
 
Well we are using winxp and using masm 6 or something like that...

Sounds right but I have no clue... (Buffered input sounds familiar)

Heres the code I have right now which computs 36+year-2000+(year * 3)%7

Code:
.model small
.stack 100h
.data
message db "Hello, world!" ,0dh,0ah, '$'

Year dw 2004
R2D2 dw ?


.code
main proc
	mov ax,@data
	mov ds, ax
	
	; mult year by 3 (ax: 177F) x
	mov dx,Year
	inc dx
	mov ax,3
	mul dx

	; (year * 3) % 7 (cx: 2) x 
	mov bx,7
	idiv bx
	mov cx,dx

	; Add 36 + year (bx: 7F9) x
	mov ax,36
	mov bx,year
	inc bx
	add bx,ax

	; sub 2000 from (36 + year) (Dx) (A: 29)
	mov ax,2000
	sub bx,ax

	; 36+year-2000+(year * 3) % 7 (A: 2B)
	add bx,cx
	
	; R2D2 (A: 2B)
	mov R2D2, bx
	

	mov ax,4C00h
	int 21h
main endp
end main

to sum things up i need to read in 4 digits (the year) to replace "year".
put the 4 ascii digits through a convertor -30h to each input. then multiple it by 10

in the form x * 10 + input with x starting at 0 and being added to each time.
0*10 + 2 = 2
2*10 + 0 = 20
20*10 +0 = 200
200*10 +4 = 2004


EDIT: Found this but its not working...

mov ah, 1h ; keyboard input subprogram
int 21h ; character input
; character is stored in al
mov c, al ; copy character from al to c

error: invalid instruction operand
which has something to do with al...
 
Well we are using winxp and using masm 6 or something like that...

Sounds right but I have no clue... (Buffered input sounds familiar)

Heres the code I have right now which computs 36+year-2000+(year * 3)%7
to sum things up i need to read in 4 digits (the year) to replace "year".
put the 4 ascii digits through a convertor -30h to each input. then multiple it by 10

in the form x * 10 + input with x starting at 0 and being added to each time.
0*10 + 2 = 2
2*10 + 0 = 20
20*10 +0 = 200
200*10 +4 = 2004


Well you already have the logic down that you need to complete so that is a good start.

If you look at Int 21h / function 0A, it puts the input string into DX.

You can then take that value, and run it through an ascii -> int converter routine you have and save the year value to some other buffer space.
 
Cant use 0A...

Heres what I have now

Code:
; Request digit 1
mov ah,9
mov dx, offset message
int 21h

; Get digit 1
mov ah,7
int 21h
mov dl,al

; Print digit 1
mov ah,2
int 21h

However for some reason this is doing some crazy shit... btw message is defined

Well shit... The problem was the friggen numpad or something for some reason when we use the normal characters it works...
 
Cant use 0A...

Heres what I have now

Code:
; Request digit 1
mov ah,9
mov dx, offset message
int 21h

; Get digit 1
mov ah,7
int 21h
mov dl,al

; Print digit 1
mov ah,2
int 21h

However for some reason this is doing some crazy shit... btw message is defined

Well shit... The problem was the friggen numpad or something for some reason when we use the normal characters it works...


Why can't you use 0A?
 
because we "havnt learned it yet" lol... The teacher is a dick...

Edit: I think the reason is so we learn how to move stuff between registers or something...
 
let me recommend a book to you if you haven't bought it yet.

http://www.amazon.com/IBM-Assembly-...=sr_1_1?ie=UTF8&s=books&qid=1237235247&sr=8-1

i have an ancient copy of this book and refer to it anytime i have something to do like this.

additionally, start with the basic basics. even though you are programming on winxp, you are actually probably programming the chip in real mode, that is, you are treating it like an i8086. you are probably using DOS constructs that have been ported to winxp.

i recommend you learn about these differences. it helps tremendously sometimes when you need to debug things.
 
As an Amazon Associate, HardForum may earn from qualifying purchases.
Back
Top